zoukankan      html  css  js  c++  java
  • curl发送请求时携带cookie-转载未验证

     1 <?php  
     2 header('Content-Type:text/html;charset=utf-8');  
     3 echo  "<pre>";  
     4   
     5 function curl($cookie,$user_agent,$destURL, $paramStr='',$flag='get',$ip='10.57.22.151',$fromurl='http://www.baidu.com'){  
     6     $curl = curl_init();  
     7     if($flag=='post'){//post传递  
     8         curl_setopt($curl, CURLOPT_POST, 1);  
     9         curl_setopt($curl, CURLOPT_POSTFIELDS, $paramStr);  
    10     }  
    11     curl_setopt($curl, CURLOPT_URL, $destURL);//地址  
    12       
    13     curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));  //构造IP  
    14       
    15       
    16     curl_setopt($curl, CURLOPT_REFERER, $fromurl);  
    17     curl_setopt($curl, CURLOPT_TIMEOUT, 10);#10s超时时间  
    18       
    19     curl_setopt ($curl, CURLOPT_USERAGENT, $user_agent);  
    20     //curl_setopt ($curl, CURLOPT_COOKIEJAR, $cookie);  
    21     curl_setopt ($curl, CURLOPT_COOKIEFILE, $cookie);  
    22       
    23     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);  
    24     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  
    25     $str = curl_exec($curl);  
    26     curl_close($curl);  
    27     return $str;  
    28 }  
    29   
    30       
    31     $postdata = 'a=11111111111';  
    32     $user_agent = "Mozilla/5.".rand(0,100)." (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0";  
    33     $cookie = 'd:cookie.txt';  
    34     $getip='66.66.'.rand(0,16).'.'.rand(0,158) ;  
    35     //file_put_contents('d:cookie.txt', '');  
    36     $cookie_file = dirname(__FILE__).'/cookie.txt';  
    37     ob_start();  
    38     $html =  curl($cookie_file,$user_agent,'http://127.0.0.50/b.php',$postdata,'post',$getip,'');  
    39     ob_end_clean();  
    40       
    41     echo $html; 

    cookie文件

     1 127.0.0.50 FALSE / FALSE 1418875953 aaaa cccc  

    转载地址:

    http://blog.csdn.net/ebw123/article/details/41980239
  • 相关阅读:
    poj2886 Who Gets the Most Candies?
    poj1201 Intervals
    poj3109 Inner Vertices
    poj1990 MooFest
    poj3368 Frequent values
    NOIP练习赛题目6
    NOIP练习赛题目5
    NOIP练习赛题目4
    NOIP练习赛题目3
    NOIP练习赛题目2
  • 原文地址:https://www.cnblogs.com/online-link/p/6143114.html
Copyright © 2011-2022 走看看