ICECMS 2015-11-25 02:00 采纳率: 0%
浏览 1851

关于curl函数使用问题

上次这个问题没人帮我解决,,,我又重新修改了一下代码。。。。。

然而还是不行

上次的问题地址

大神帮我看看哪里有问题

 <?php



function curl($url,$cookie,$httpheader,$referer="http://icecms.cn",$follow=1,$header=1){
        //$ch = curl_init("http://tool.yswl.pw/ua");
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
        curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36');
        curl_setopt($ch, CURLOPT_REFERER, $referer);       //伪装REFERER
        curl_setopt($ch, CURLOPT_HEADER, $header);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate,sdch');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,$follow);//跟随重定向
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
        /*curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
        curl_setopt($ch, CURLOPT_PROXY, "203.195.162.96"); //代理服务器地址
        curl_setopt($ch, CURLOPT_PROXYPORT, 80); //代理服务器端口
        curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式*/
        $result=curl_exec($ch);
        curl_close($ch);
        return $result;
    }


    $httpheader = array( 
        'CLIENT-IP:113.105.123.123', 
        'X-FORWARDED-FOR:113.105.123.123', 
        'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    ); 

    $cookie_file = dirname(__FILE__)."/cookie.txt";
    //首次访问
    $url="http://icsr.cn/a.asp?icecms";
    $contents1=curl($url,$cookie_file,$httpheader);
    //带上首次访问得到的cookie访问跳转的链接
    preg_match('/href="(.*)"/isU',$body,$inarr1);
    echo $tourl="http://icsr.cn".$inarr1[1];
    $contents2=curl($tourl,$cookie_file,$httpheader);
    //获取重定向 的地址
    //preg_match_all( "/Location:(.*?)rn/" , implode( "rn" , $contents2 ),  $cookies );
    //echo $url2=$cookies[1];
//  $contents3=curl($url2,$cookie_file,$httpheader);





    $fp = @fopen("Log.html", "w"); //记录捕获到的页面源码
    fwrite($fp,$contents1); 
    fclose($fp);

    $fp = @fopen("Log1.html", "w"); //记录捕获到的页面源码
    fwrite($fp,$contents2); 
    fclose($fp);

//  $fp = @fopen("Log2.html", "w"); //记录捕获到的页面源码
//  fwrite($fp,$contents3); 
//  fclose($fp);
?>


就是打算用监控宝监控这个程序,模拟着一天24小时不停地有人访问这个上面那个网址。。。

  • 写回答

3条回答

  • 紫气天堂 2015-11-25 02:40
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致