cURL PHP-Login to Yahoo Problem

I’m trying to login to Yahoo using cURL PHP. I can successfully login through the first set of curl_init():


$agent_name = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; Tablet PC 2.0; .NET CLR 1.1.4322)";
//$agent_name = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10";

$c=curl_init();
curl_setopt($c, CURLOPT_USERAGENT, "$agent_name");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
/*curl_setopt($c, CURLOPT_COOKIEJAR, "./cookie.txt");
curl_setopt($c, CURLOPT_COOKIEFILE, "./cookie.txt");*/
curl_setopt($c, CURLOPT_COOKIEJAR, "c:\cookie.txt");
curl_setopt($c, CURLOPT_COOKIEFILE, "c:\cookie.txt");
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_URL, "https://login.yahoo.com/config/login?rl=1");
$html=curl_exec($c);
curl_close($c);

However, when I go through the second set of curl_init():


/*
 * Get form's action url
 */
preg_match("/action=\"([\S]*)\" /", $html, $action);
$url = $action[1];

/*
 * Get input type=hidden name and values
 */
preg_match_all("/<input type=\"hidden\" name=\"(.*)\" value=\"(.*)\">/", $html, $hidden_vars);

$params = array();

foreach($hidden_vars[1] as $index => $name)
        $params[$name] = $hidden_vars[2][$index];

$params['.done'] = "http://my.yahoo.com/";
$params['.persistent']  = "n";
$params['.save']                = "Sign In";
$params['login']                = $loginUser;
$params['passwd']               = $password;

$c=curl_init();
curl_setopt($c, CURLOPT_USERAGENT, "$agent_name");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($c, CURLOPT_URL, $url);
/*curl_setopt($c, CURLOPT_COOKIEJAR, "./cookie.txt");
curl_setopt($c, CURLOPT_COOKIEFILE, "./cookie.txt");*/
curl_setopt($c, CURLOPT_COOKIEJAR, "c:\cookie.txt");
curl_setopt($c, CURLOPT_COOKIEFILE, "c:\cookie.txt");
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_REFERER, "https://login.yahoo.com/config/login?rl=1");

$result = curl_exec($c);
$file = time().'.txt';
//touch($file);
$fh = fopen($file,'w');
fwrite($fh,$result);
fclose($fh);
$info = curl_getinfo($c);
$curlError = curl_error($c);
curl_close($c);

The last bit of code with the fopen() simply saves the output of the last curl_init() execution to a file so I can see what the problem may be. The contents of the $result variable is the output of the webpage.

This is the contents of the file:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
<!--
window.location.replace("http://my.yahoo.com/");
// -->
</script>
<meta http-equiv="Refresh" content="0; url=http://my.yahoo.com/">
</head>
<body>
If you are seeing this page, your browser settings prevent you
from automatically redirecting to a new URL.
<p>
Please <a href="http://my.yahoo.com/">click here</a> to continue.
</body>
</html>
<!-- l14.member.sp1.yahoo.com uncompressed/chunked Tue Jun  2 18:54:07 PDT 2009 -->

I have no idea why this doesn’t work. I am looking into this problem and will post in a later blog for the solution.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Share

You must be logged in to post a comment.