Putting a login form on another site

SteveTurnbull - December 3, 2008 - 12:36

I am developing a site which allows other (unrelated) sites to have a login form.

I have managed this reasonably easily by creating a module which builds a path 'external/login' and then inserting:

<?php
 
echo file_get_contents('http://www.example.com/external/login') ;
?>

into the page on the unrelated site. When this URL is accessed, the module on my site fetches the standard user/login block contents, converts all the relative URLs to absolute URLs and delivers the HTML (using print/exit). This all seems to work okay.

However the user might already be logged in, but the file_get_contents() function behaves as if it's an anonymous user and doesn't know anything about being logged in or not.

Is there any way, using file_get_contents() (or something else if necessary, cURL?) to communicate the actual logged-in-or-not state of the user (if he is logged in) so that I can decide whether to fetch the login block, or something else?

TIA

Steve

Partial solution

SteveTurnbull - December 3, 2008 - 13:27

Having studied the parameters of file_get_contents() (http://www.php.net/file_get_contents) and stream_context_create() (http://www.php.net/manual/en/function.stream-context-create.php) apparently it is possible to put cookie data into a file_get_contents() call but getting the information is another issue.

Although it's more of a PHP thing - but if anyone knows how to get the necessary cookie data I'd appreciate some pointers.

Steve Turnbull

Drupal Contractor in the UK
http://www.endclub.com/
http://www.clashmusic.com/
http://www.nsonline.org.uk/

 
 

Drupal is a registered trademark of Dries Buytaert.