我已經寫了一個php腳本來從curl登錄到一個網站。下面是我的代碼:如何檢查登錄成功在PHP curron?
<?php
// INIT CURL
$ch = curl_init();
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'http://wordpress.dev/wp-login.php');
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'log=admin&pwd=admin');
// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);
var_dump($store);exit;
// CLOSE CURL
curl_close ($ch);
?>
如果我給正確的密碼,它提供的字符串()「,如果給出錯誤的密碼,它重定向我 登錄頁面如何檢查登錄成功
curl_exec返回字符串告訴你結果。 – 2013-02-12 11:56:46
如果你有答案,請接受它。 – 2014-11-20 05:54:57