NYCPHP Meetup

[nycphp-talk] cURL login to Squirrelmail

Dan Cech dcech at phpwerx.net
Mon Jan 17 18:37:32 EST 2005


Jeffrey Stevison wrote:
> I'm using the following to automatically login users to their web based  
> email from our intranet.  I get a message from the browser "Can't open  
> page blah because it could not load any data from this location"

I managed to get the cURL call to work in that it can successfully log 
in, however you can't just redirect the user this simply.

The problem is that sqmail remembers the user by setting cookies, if you 
log them in this way it can't set the required cookies and the user 
would be logged out again as soon as they clicked on anything.

The easiest way to make a 'my email' link is to use a hidden form which 
points to 'http://mysite/webmail/src/redirect.php'.

Something like this ought to do the trick:

<form action="http://mysite/webmail/src/redirect.php" method="POST">
   <input type="hidden" name="login_username" value="<?php print 
$_SESSION['Username'];?>" />
   <input type="hidden" name="secretkey" value="<?php print 
$_SESSION['Password'];?>" />
   <input type="hidden" name="js_autodetect_results" value="0" />
   <input type="hidden" name="just_logged_in" value="1" />

   <input type="submit" value="Login" />
</form>

If you really don't want to have the password on the page it may be 
possible to use the curl request to get the headers then parse out the 
cookies and set them on the user's machine, though this will most likely 
require that your script and the sqmail instance are on the same domain.

Dan

> I'm not sure if the problem is with my cURL code or squirrelmail.  Here  
> is the code:
> 
>     session_start();
> 
>     $ch = curl_init();
>     
>     curl_setopt($ch, CURLOPT_URL,"http://mysite/webmail/src/redirect.php");
>     curl_setopt($ch, CURLOPT_POST, 1);
>     curl_setopt($ch, CURLOPT_POSTFIELDS,  
> "login_username=".$_SESSION['Username']."&secretkey=".$_SESSION['Passwor 
> d']."&js_autodetect_results=0&just_logged_in=1");
>     curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
>     
>     curl_exec ($ch);
>     curl_close ($ch);
> 
> 
> Jeff
> 
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.newyorkphp.org



More information about the talk mailing list