1
我試圖使用以下代碼登錄網站。它有一個彈出消息使用cURL從我的網站登錄HTTPS網站
「雖然此頁面已被加密,但您輸入的信息將通過未加密的連接發送,並且很容易被第三方讀取。您確定要繼續發送此信息嗎? 「
在授予訪問權限之前,需要點擊「繼續」按鈕。
該代碼不起作用,我不確定它是否與消息有關或者我沒有做對的事情?
$url = "https://anothersite.com/login.php";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/A.B (KHTML, like Gecko) Chrome/X.Y.Z.W Safari/A.B.";
$username = "xxxx";
$password = "1234";
$postfields = "username=".$username."&password=".$password;
$cookie_file_path = getcwd().'/cookie.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_POST, 1);
echo curl_exec($ch);
curl_close($ch);
'curl_setopt($ CH,CURLOPT_SSL_VERIFYPEER,FALSE);'的值設置CURLOPT_SSL_VERIFYPEER應該是一個布爾值:http://php.net/manual/en/function.curl-setopt.php – cheesemacfly
感謝@cheesemacfly –
第一次調用是正確的(它應該是一個整數),所以它會是'curl_setopt($ ch,CURLOPT_SSL_VERIFYHOST,0);' – cheesemacfly