0
我想從私人論壇中提取一些數據。我創建了一個使用CURL登錄的PHP腳本,並使用DOMDocument來提取頁面數據。PHP Curl登錄論壇,但不會保持登錄狀態?
我已成功使用腳本登錄,但它的行爲就像我嘗試使用loadHTMLFile()加載網頁時從未登錄一樣。
有人告訴我可能需要發送cookie標頭嗎?但我不知道該怎麼做,或者甚至有必要。
任何人有任何想法?
<?
function vBulletinLogin($user, $pass)
{
$md5Pass = md5($pass);
$data = "do=login&url=index.php&vb_login_md5password=$md5Pass&vb_login_username=$user&cookieuser=1";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "****"); // replace ** with tt
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt ($ch, CURLOPT_TIMEOUT, '10');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/public_html/phpcrawl/cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/public_html/phpcrawl/cookies.txt");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERRER, "****");
$store = curl_exec ($ch);
echo $store; <- **this shows that I have successully logged in, it gives me a welcome message**
print_r($_COOKIE);
curl_close($ch);
$pos = strpos($store, "Thank you for logging in");
if($pos === FALSE) RETURN 0;
else RETURN 1;
}
if(vBulletinLogin("****","****")) echo "Logged In";
else echo "Failed to Login check User/Pass";
$url="http://texturl.com";
echo $url."<br>";
//get new HTML document
$html = new DOMDocument();
$html->loadHTMLFile($url);
print $html->saveHTML(); <- shows a login and password box saying I am not logged in.
非常感謝您的幫助。得到它的工作。 – 2010-11-23 04:37:50