Quantcast
Channel: Creating a web service in PHP - Stack Overflow
Viewing all articles
Browse latest Browse all 8

Answer by Silviu-Marian for Creating a web service in PHP

$
0
0

Easiest way in PHP is to use GET/POST as data-in and echo as data-out.Here's a sample:

<?php if(empty($_GET['method'])) die('no method specified');switch($_GET['method']){   case 'add': {        if(empty($_GET['a']) || empty($_GET['b'])) die("Please provide two numbers. ");       if(!is_numeric($_GET['a']) || !is_numeric($_GET['b'])) die("Those aren't numbers, please provide numbers. ");       die(''.($_GET['a']+$_GET['b']));       break;    }}

Save this as test.php and go to http://localhost/test.php?method=add&a=2&b=3 (or wherever your webserver is) and it should say 5.


Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>