我遇到了用我写的PHP代码登录到Yahoo的问题。该代码工作较早,但由于某种原因,它停止工作。它总是显示雅虎登录页面,顶部有我的用户名,如Hi Sudhir
在标题处,就好像我已经登录了,还有我的雅虎用户名,但又显示密码字段和登录按钮,并再次显示Please Verify your password
。在php中使用cURL登录到Yahoo的问题
虽然我试图再次采取新的表单动作https://login.yahoo.com/config/login_verify2?
重新发送请求,但它不断显示相同的页面。以下是我完整的雅虎登录代码。
请建议我做错了什么,或者我错过了什么?
<?php
$yahooCalUrl = "http://calendar.yahoo.com";
$ch = curl_init($yahooCalUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies_new.txt");
//curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies_new.txt");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$resCalUrl = curl_exec($ch);
//echo $resCalUrl;
$loginUrl = "https://login.yahoo.com/config/login?";
//get the hidden values
$searchStr = "/name=\".u\" value=\"(.*?)\"/";
preg_match($searchStr, $resCalUrl, $matches);
$u = $matches[1];
$searchStr1 = "/name=\".challenge\" value=\"(.*?)\"/";
preg_match($searchStr1, $resCalUrl, $matches1);
$challenge = $matches1[1];
$searchStr2 = "/name=\".pd\" value=\"(.*?)\"/";
preg_match($searchStr2, $resCalUrl, $matches2);
$pd = $matches2[1];
$username = "my_yahoo_username";
$password = "my_yahoo_password";
//$mdPassword = md5($password);
//$finalPass = $mdPassword . $challenge;
//$hash = md5($finalPass);
//$finalHash = urlencode($hash);
$done = urlencode("http://calendar.yahoo.com");
$postFields = ".tries=1&.src=fpctx&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=".$u."&.v=0&.challenge=".$challenge."&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fwww.yahoo.com%2F&.pd=fpctx_ver%3D0%26c%3D%26ivt%3D%26sg%3D&pad=3&aad=3&login=".$username."&passwd=".$password."&.save=&passwd_raw=";
//$postFields = ".tries=1&.src=&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=&.partner=&.u=".$u."&.v=0&.challenge=".$challenge."&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=1&.chkP=Y&.pd=".$pd."&pad=6&aad=6&.persistent=&.save=1&login=".$username."&passwd=".$password."&.done=".$done;
curl_setopt($ch, curlOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_REFERER, $loginUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies_new.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies_new.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$finalLoggedIn = curl_exec($ch);
echo $finalLoggedIn;
?>
虽然我尝试使用密码哈希值,即雅虎的动态信道值与我的密码组合,但它也不能工作了这种方式。
也许一个愚蠢的问题,但你还能登录“正常”的方式?另外,请检查登录时正在发送的标题。也许他们的形式已经发生了变化! – ChrisH 2011-03-25 09:57:00
上面的代码在我的本地服务器上工作正常,但是当我将它上载到活服务器时,它根本不起作用,始终保持显示登录页面。我现场有一台Linux服务器。可能是什么问题呢..?请建议 – 2011-03-29 07:40:28
请检查您是否具有相同的PHP.ini设置,适用于实况和本地。请确保你也显示了所有的错误'ini_set('display_errors','on'); error_reporting(E_ALL);' – ChrisH 2011-03-29 09:39:22