我遇到了用我寫的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