我使用file_get_contents这个函数获取http://mixiaba.com/diy/iphoneok.asp?sid=null&pov=5这个页面参数的时候每次都是提示Warning : file_get_contents(http://mixiaba.com/diy/iphoneok.asp?sid=null&pov=5) [ function.file-get-contents ]: failed to open stream: Redirection limit reached, aborting in /home/ghlin/public_html/gphone.php on line 3怎么办啊?用了curl和fopen都无效,求解决,他们说那边服务器要user_Agent,模拟出来之后也无效,怎么办?
<?php
$url="http://mixiaba.com/diy/iphoneok.asp?sid=null&pov=5";
$postdata="cc=1&content=go&sidd=AR1orp6q9M2O5kgG5gmrhh6T&uaa=1&bq=7337&63o21k31=1";
//定义函
function post_curl($url,$postdata){
$ch=curl_init();
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);
ob_start();
curl_exec($ch);
$result=ob_get_contents();
ob_end_clean();
echo $result;
}
echo post_curl($url,$postdata);
?>
目的是让它返回$url的内容!
CURLOPT_RETURNTRANSFER TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
即可直接curl_exec得到结果。
在提交的页面取得cookie 数据然后提交.
得模拟手机浏览器提交,这个参数你得自己去找一下.
<?php
$url='http://www.bamuyu.com/news/zixun/list_7_2.html';
$content=curl_file_get_contents($url);
echo $content;
function curl_file_get_contents($durl){
$cookie_file = dirname(__FILE__)."/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $durl);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}