PHP curl login to Yahoo email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jozard
Forum Newbie
Posts: 4
Joined: Sun Jan 21, 2007 10:43 am

PHP curl login to Yahoo email

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Just out of curiosity, why would you want to login to another website from your own...?
jozard
Forum Newbie
Posts: 4
Joined: Sun Jan 21, 2007 10:43 am

Post 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]
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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/
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

I imagine that it has nothing to do with your script, but that Yahoo is checking the referrer URL.
jozard
Forum Newbie
Posts: 4
Joined: Sun Jan 21, 2007 10:43 am

Post by jozard »

i assume they check referrer, thats why this line exists:

Code: Select all

curl_setopt($ch, CURLOPT_REFERER, $varURL1 );
jozard
Forum Newbie
Posts: 4
Joined: Sun Jan 21, 2007 10:43 am

if anyone knows something about aol/hotmail

Post by jozard »

if anyone knows something about aol/hotmail it would also help
Post Reply