Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > 'Return values' from links
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 3rd July 16:32
phpmail
External User
 
Posts: 1
Default 'Return values' from links



Yes; some kind of Remote Procedure Call protocol (eg SOAP) is designed for
this. But the lightweight way would be something like:

function get_token_validity ($token)
{
$token = 'token=' . rawurlencode ($token); // armour message for sending
$host = 'www.webserverA.com';
if (($sp = fsockopen ($host, 80)) == FALSE)
{
return (NULL);
}

fputs ($sp, "POST /path/to/script.php HTTP/1.0\r\n");
fputs ($sp, "Host: $host\r\n");
fputs ($sp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs ($sp, "Content-length: " . strlen ($token) . "\r\n\r\n");
fputs ($sp, "$token\r\n");

$result = NULL;
while (!feof ($sp)) {
$a = fgets ($sp);
if (is_numeric ($a))
{
if ($a == FALSE)
{
$result = FALSE;
} else {
$result = TRUE;
}
}
}

fclose ($sp);
return ($result);
}

Untested, but it should be pretty close. Returns TRUE on a valid result,
FALSE on invalid and NULL on error.

The paired script on www.webserverA.com should just echo(1) or echo(0) for a
good or bad result.

/Ah/. I have to ask... why?

I have no idea whether the above code will run on PHP 3.
  Reply With Quote


 


2 3rd July 16:33
pmorgan
External User
 
Posts: 1
Default 'Return values' from links



Some XML would do the trick

pete
  Reply With Quote
3 3rd July 16:34
phpmail
External User
 
Posts: 1
Default 'Return values' from links


Sorry. That should be HTTP/1.1, of course.
  Reply With Quote
Reply


Thread Tools
Display Modes




666