Linker IT Software
Google
Web www.oraxcel.com
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
Simple php web service without using toolkits (Read 2688 times)
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Simple php web service without using toolkits
28.10.06 at 16:47:30
 
Simple php web service without using toolkits
 
I was researching how to remotely call a function in php. To make a remote function call you cannot simply use an include or require statement to include the function in php. The alternatives is to use SOAP and there are a few other methods to implement such a web service. All this require quite a bit of programming. On the consumer side it is not soo bad but to implement the server is quite a nightmare.
 
I found that with a simple techneque you can call a remote script and send a return value back, just like you do when you call a function.
 
I used the file_get_contents function in PHP. With this function youc an make a call to a url and catch the results into a variable. Example:
 
$result = file_get_contents('http://www.mysite.com/myscript.php');
 
To pass parameters I used variables in the url:
$result = file_get_contents('http://www.mysite.com/myscript.php?a=1&b=2');
 
Now this looks like a function! The remote script should echo the result. That can the be captured in the result variable.
 
The remote script may be coded as follows:
myscript.php:
Code:
<?php
  $a = $_GET['a']; 
  $b = $_GET['b'];
  if($a==$b)
  {  echo "ok";
  }
  else
  {  echo "not ok";
  }
?>
 


 
The above function takes two parameters: a and b. It returns a string which contains "ok" when a=b and "not ok" otherwise.
Back to top
 
« Last Edit: 28.10.06 at 17:21:03 by Gerrit-Jan Linker »  

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1