是的,是的,我知道用戶名和密碼。如何從PHP身份驗證背後的網站中大量獲取頁面
我需要一些技巧在PHP中登錄到一個網站和檢索一些圖像/內容,像一個普通的網站。
很明顯,使用捲曲file_get_contents它不起作用,因爲我沒有通過身份驗證。
我該怎麼辦?
驗證是正常的HTTP驗證與POST。
編輯:好的謝謝你的幫助!
我張貼在這裏工作的代碼以供將來參考
//login and set cookie
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, "cookiefile");
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile"); # SAME cookiefile
curl_setopt($curl, CURLOPT_URL, "url in which there is the login form");
curl_setopt($curl, CURLOPT_POSTFIELDS, "user=test&password=test&someparam=somevalue"); //put here the post/get values
$output = curl_exec($curl);
echo $output;
//finally fetch my content
curl_setopt($curl, CURLOPT_URL, $url_to_fetch);
$output = curl_exec($curl);
echo $output;
curl_close ($curl);
您是否需要使用PHP以編程方式執行此操作。如果沒有,請嘗試使用wget或類似的東西。網站使用什麼樣的認證?一個HTML表單或HTTP基本認證,或更奇特的東西? – fmark 2010-05-20 15:39:10