Page 1 of 1

PHP curl login to Yahoo email

Posted: Sun Jan 21, 2007 11:00 am
by jozard
hi, i'm new here, and i heard somewhere that the pro's are here.
I've been breaking my head about that for weeks now:

I'm trying to create a program that automatically logs in to Yahoo/AOL webmail (with my user and password).

I analyzed all they're hidden fields and all, and still something does not seem to work!!
if anyone here could help me i'd be greatful

Code: Select all

function HiddenFields($contents)
{

	preg_match('/name="login_form">[\s\S]*yreglgtb/',$contents,$matches);
	$str= implode(';',$matches);
	$matches2= explode ('<',$str);

	//------------ creating $params (all hidden fields) ------------
	$names='';
	$n=1;
	while ($n+1 < count($matches2))
	{
		$str1=$matches2[$n];
		preg_match('/name="[\s\S]*" value/',$str1,$match);
		$value = str_replace('name="','',$match[0]);
		$value = str_replace('" value','',$value);
		$names.=$value.';';
		$n++;
	}
	$names = explode (';',$names);

	$values='';
	$n=1;
	while ($n+1 < count($matches2))
	{
		$str1=$matches2[$n];
		preg_match('/value="[\s\S]*">/',$str1,$match);
		$value = str_replace('value="','',$match[0]);
		$value = str_replace('">','',$value);
		$values.=$value.';';
		$n++;
	}
	$values = explode (';',$values);

	$params='';
	$n=0;
	while ($n+1 < count($names))
	{
		$params.=$names[$n].'='.$values[$n].'&';
		$n++;
	}
	
	return $params;
	
} //HiddenFields
this function takes all the hidden fields in the specific login form and returns it into $params as $params[n]='name=value&'

Code: Select all

$varURL1 = 'https://login.yahoo.com/config/mail';

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_URL,$varURL1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

$contents=curl_exec($ch);
curl_close($ch); 
$params = HiddenFields($contents);

$params.= 'login='.$username;
$params.= '&passwd='.$password;
$params.= '&.save=Sign In';


$varURL2='https://login.yahoo.com/config/login?';
$varURL2='https://login.yahoo.com/config/login?';

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_REFERER, $varURL1 );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_URL,$varURL2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

echo $content=curl_exec($ch);

curl_close($ch); ?>
thanks

Posted: Sun Jan 21, 2007 11:08 am
by superdezign
Just out of curiosity, why would you want to login to another website from your own...?

Posted: Sun Jan 21, 2007 11:14 am
by jozard
actually its for a little service to grab emails from the inbox and search a certain phrase in them.

it just keeps dumping me back to the login page.[/syntax][/list]

Posted: Sun Jan 21, 2007 4:07 pm
by hawleyjr
superdezign wrote:Just out of curiosity, why would you want to login to another website from your own...?
Why not? I wrote an application a few years ago that would check my pop3 email because my current employer blocked outside email...;)

Edit: BTW/ Have you looked into Yahoo's API?

http://developer.yahoo.com/auth/

Posted: Sun Jan 21, 2007 7:00 pm
by aaronhall
I imagine that it has nothing to do with your script, but that Yahoo is checking the referrer URL.

Posted: Mon Jan 22, 2007 3:58 am
by jozard
i assume they check referrer, thats why this line exists:

Code: Select all

curl_setopt($ch, CURLOPT_REFERER, $varURL1 );

if anyone knows something about aol/hotmail

Posted: Thu Jan 25, 2007 6:33 am
by jozard
if anyone knows something about aol/hotmail it would also help