是的,是的,我知道用户名和密码。如何从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