0
嘗試使用curl和php登錄到遠程服務器,但獲取有關未啓用cookie的錯誤。這裏是我的代碼:使用curl和php登錄到遠程服務器
error_reporting(E_ALL);
ini_set("display_errors", 1);
$url = 'http://uk.songselect.com/account/login/';
$username = '*****';
$password = '******';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'tmp/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmp/cookie.txt');
//run the process and fetch the document
$doc = curl_exec($ch);
// extract __RequestVerificationToken input field
preg_match('#<input name="__RequestVerificationToken" type="hidden" value="(.*?)"#is', $doc, $match);
$token = $match[1];
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, '__RequestVerificationToken='.$token.'&UserName='.$username.'&Password='.$password.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//run the process and fetch the document
$doc = curl_exec($ch);
echo $doc;
//terminate curl process
curl_close($ch);
//print output
echo $token;
這是我收到的錯誤:「你需要在你的瀏覽器使用SongSelect網站作爲身份驗證的用戶啓用cookie」
任何想法爲什麼會發生這種情況?
謝謝!
試過了,它不會改變任何東西。仍然得到相同的錯誤 –