curl发送请求时携带cookie-转载未验证
Posted 凌晨两点一刻
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于curl发送请求时携带cookie-转载未验证的主要内容,如果未能解决你的问题,请参考以下文章