cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Log to mail.yahoo.com

From: <feelfree_at_noisy.ch>
Date: Thu, 18 Aug 2005 14:00:22 +0200

Hello everyone,

I try to reach my yahoo mail by using curl functions in php... every thing goes
well except the last step :( I give you my code (it a bit long, but very
repeatitive)...

function get_hiddeninput($header){
        ...to get the content of <input type=hidden...
}

function get_cookies($header){

            ... to get the cookies from the headers...
}

// Step1: connection to mail.yahoo.com

$url = 'http://mail.yahoo.com';
$agt = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
$Q = 'q1=AACAAAAAAAAAAA--&q2=QwNEag--'; // seems to be fixed
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agt);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
$resultat = curl_exec($ch);
curl_close($ch);

$hidden = get_hiddeninput($resultat);
$login = 'XXXXXX';
$pwd = 'YYYYYY';
$pwd = md5(md5($pwd).$hidden[12]);// hidden[12] is the challenge

$postdata='.tries='.$hidden[0].'&.src='.$hidden[1].'&.md5='.$hidden[2].'&';
$postdata.='.hash='.$hidden[3].'&.js='.$hidden[4].'&.last='.$hidden[5].'&';
$postdata.='promo='.$hidden[6].'&.intl='.$hidden[7].'&.bypass='.$hidden[8].'&';
$postdata.='.partner='.$hidden[9].'&.u='.$hidden[10].'&.v='.$hidden[11].'&';
$postdata.='.challenge='.$hidden[12].'&.yplus='.$hidden[13].'&.emailCode='.$hidden[14].'&';
$postdata.='pkg='.$hidden[15].'&stepid='.$hidden[16].'&.ev='.$hidden[17].'&';
$postdata.='hasMsgr='.$hidden[18].'&.chkP='.$hidden[19].'&.done='.$hidden[20].'&';
$postdata.='login='.$login.'&passwd='.$pwd.'&.save=1&.hash=1&.md5=1';
$postdata = str_replace(':','%3A',$postdata);

$getdata= get_cookies($resultat).';Q='.$Q;

// step2: reach http://login.yahoo.com/config/login
$url=
'http://us.rd.yahoo.com/reg/login0/no_suli/login/us/ym/*http://login.yahoo.com/config/login';

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url.'?'.$postdata);
curl_setopt($ch, CURLOPT_USERAGENT, $agt);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_COOKIE,$getdata);
$resultat = curl_exec($ch);
curl_close($ch);

$postdata='.tries='.$hidden[0].'&.src='.$hidden[1].'&.md5='.$hidden[2].'&';
$postdata.='.hash='.$hidden[3].'&.js=1'.$hidden[4].'&.last='.$hidden[5].'&';
$postdata.='promo='.$hidden[6].'&.intl='.$hidden[7].'&.bypass='.$hidden[8].'&';
$postdata.='.partner='.$hidden[9].'&.u='.$hidden[10].'&.v='.$hidden[11].'&';
$postdata.='.challenge='.$hidden[12].'&.yplus='.$hidden[13].'&.emailCode='.$hidden[14].'&';
$postdata.='pkg='.$hidden[15].'&stepid='.$hidden[16].'&.ev='.$hidden[17].'&';
$postdata.='hasMsgr=1&.chkP='.$hidden[19].'&.done='.$hidden[20].'&';
$postdata.='login='.$login.'&passwd='.$pwd.'&.persistent=&.save=1&.hash=1&.md5=1';
$postdata = str_replace(':','%3A',$postdata);

// Step3: http://login.yahoo.com/config/login

$url = 'http://login.yahoo.com/config/login';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url.'?'.$postdata);
curl_setopt($ch, CURLOPT_USERAGENT, $agt);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_COOKIE,$getdata);
$resultat = curl_exec($ch);
curl_close($ch);
$cookie = get_cookies($resultat);

//////////////////////////////////////////////////////////////////
// all data have been verified, everything works well until here
//////////////////////////////////////////////////////////////////

// Problems start now...

// Step4:

preg_match_all("!Location: (.*)!", $resultat, $url);
$url = $url[1][0];
// url is something like
http://login.yahoo.com/config/verify?.done=http%3a//fr.f869.mail.yahoo.com/ym/login%3f.rand=fv9vf68anl8v6

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agt);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_COOKIE,$cookie);//$getdata.';'.$cookie;
$resultat = curl_exec($ch);
curl_close($ch);

This last part do not work at all... and I really do not understand why: if I
look at the headers, I have the feeling I do well... The answer I receive is
"The browser you're using refuses to sign in. (cookies rejected)"...

Does anybody have an idea?!

BR, ff.
Received on 2005-08-18