我使用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,模拟出来之后也无效,怎么办?

解决方案 »

  1.   

    curl 里有个设置跟随页面的重定向curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); 
      

  2.   

    还是失败,大家帮帮忙,我把代码贴出来
    <?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的内容!
      

  3.   

    1,return $result;2,http://www.php.net/manual/en/function.curl-setopt.php设置
    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得到结果。
      

  4.   

    稍微看了看,cookie是必须要加的.先读页面获取cookie 然后带上cookie提交.另外你这个不是手机发布的地方嘛,后台过滤掉非手机发布的信息应该是可行的吧.
      

  5.   

    唉,怎么做啊,我想获取那个页面的内容,并模拟post提交到那里去。行的通吗?
      

  6.   


    在提交的页面取得cookie 数据然后提交.
    得模拟手机浏览器提交,这个参数你得自己去找一下.
      

  7.   


    <?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;
     }