php curl携带 cookie 请求

<?php
header('Content-Type:text/html;charset=utf-8');
echo  "<pre>";

function curl($cookie,$user_agent,$destURL, $paramStr='',$flag='get',$ip='10.57.22.151',$fromurl='http://www.baidu.com'){
	$curl = curl_init();
	if($flag=='post'){//post传递
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $paramStr);
	}
	curl_setopt($curl, CURLOPT_URL, $destURL);//地址
	
	curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));  //构造IP
	
	
	curl_setopt($curl, CURLOPT_REFERER, $fromurl);
	curl_setopt($curl, CURLOPT_TIMEOUT, 10);#10s超时时间
	
	curl_setopt ($curl, CURLOPT_USERAGENT, $user_agent);
	//curl_setopt ($curl, CURLOPT_COOKIEJAR, $cookie);
	curl_setopt ($curl, CURLOPT_COOKIEFILE, $cookie);
	
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$str = curl_exec($curl);
	curl_close($curl);
	return $str;
}

	
	$postdata = 'a=11111111111';
	$user_agent = "Mozilla/5.".rand(0,100)." (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0";
	$cookie = 'd:\cookie.txt';
	$getip='66.66.'.rand(0,16).'.'.rand(0,158) ;
	//file_put_contents('d:\cookie.txt', '');
	$cookie_file = dirname(__FILE__).'/cookie.txt';
	ob_start();
	$html =  curl($cookie_file,$user_agent,'http://127.0.0.50/b.php',$postdata,'post',$getip,'');
	ob_end_clean();
	
	echo $html;
	
	

cookie 文件 

127.0.0.50	FALSE	/	FALSE	1418875953	aaaa	cccc



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值