[PHP] 'Return values' from links

2003-10-17 Thread akroeger1
First of all, Hi!
I just started getting into php a week ago, but already ran into a problem I
can't seem to solve.
The issue is this : I code 2 different websites, each has it's own mySQL-DB.
Website A has a login-section, each time you successfully log in, a key is
generated which stays only valid for a certain period of time (done via
database).
Now, I have a link from the login section on website A to a sign-up-form on
website B. This sign-up is supposed to only be accessible if you have a valid
key from website A, which qualifies you as a member.
Website B lets you fill out the form no matter what key you offer it, but
when you have finished, right before I insert the data into my DB, I want it to
check back with website A whether the key is valid or not. 

That's where I'm stuck right now. 
I have a php file in website A's directory, which, when given a key value,
will check whether it is valid or not. Is there any way I can treat this
website like a function and have it give me a return value after it has run
through ?
I tried it by putting a header from B to validate.php on A, and have that
only call the 'exit;' when a valid key is provided, but it seems to proceed
with website B's code no matter what the header to website A does.

Is there any other way or workaround that I can accomplish this ? I just
need a link to that validation page, and after the link the code should proceed
or not based on the return value from that link.

By the way, I work with php3, so I hope there's a solution for that version
;)
Thanks in advance for any help, I hope my english wasn't too bad for you to
understand what I meant.

-- 
NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService

Jetzt kostenlos anmelden unter http://www.gmx.net

+++ GMX - die erste Adresse für Mail, Message, More! +++

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'Return values' from links

2003-10-17 Thread David Otton
On Fri, 17 Oct 2003 08:54:23 +0200 (MEST), you wrote:

I have a php file in website A's directory, which, when given a key value,
will check whether it is valid or not. Is there any way I can treat this
website like a function and have it give me a return value after it has run
through ?

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.

By the way, I work with php3, so I hope there's a solution for that version
;)

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

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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'Return values' from links

2003-10-17 Thread David Otton
fputs ($sp, POST /path/to/script.php HTTP/1.0\r\n);
fputs ($sp, Host: $host\r\n);

Sorry. That should be HTTP/1.1, of course.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php