Sunday, May 27, 2007

Web Services in PHP 4

I have a situation where I need to use a web service in PHP 4. I found a piece of free PHP code call nusoap and in this site created /lib/nusoap for all of its code. Here are some helpful snippets to access the web service methods and data.
require_once('lib/nusoap/nusoap.php');
$wsdl = "http://service.domain.com/ws.asmx?WSDL";
$client = new soapclient($wsdl, 'wsdl');
$proxy = $client->getProxy();
$authResponse = $proxy->authenticate_token(array('token_id'=>$cToken, 'site_code'=>$WS_SITE_CODE));
if($authResponse['authenticate_tokenResult'] == 'true')
{
setcookie("mytoken", $cToken, 0, "/", ".mydomain.com");
// Modified to work on www and non-www usage of the domain.
}
$authInfoResponse = $proxy->authenticate_passive(array('ip'=>$cIP, 'referrer'=>$cRef));
$authArrayResponse = $authInfoResponse['authenticate_passiveResult'];
$token_id = $authArrayResponse['token_id'];
if ($token_id != "0" && $token_id != "")
{
setcookie("mytoken", $token_id, 0, "/", ".mydomain.com");
}

No comments: