php curl模拟登陆

$url="url地址";
$post_file="username=xxx&password=xxx";
$cookie_jar = dirname(__FILE__)."/pic.cookie";
$curl = curl_init();
curl_setopt( $curl,CURLOPT_URL,$url );
curl_setopt( $curl,CURLOPT_RETURNTRANSFER,true );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//规避证书
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 防止302 盗链
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_file);//要提交的信息 
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar); //设置Cookie信息保存在指定的文件中 

$output = curl_exec( $curl );
curl_close( $curl );
        
print_r($output);
        
        
$urldata = "要操作的url带cookie的";
$post = "content=立马开始灌水啦&shopid=232";
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $urldata);  //设置curl
	
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //post数据
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar); //读取jar

$output2 = curl_exec($ch);    //发送HTTP请求 
curl_close($ch); 

print_r($output2);
//获取指定页面
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);        
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
$html=curl_exec($ch);
// var_dump($html);
curl_close($ch);
	
	@承鹏辉


你可能感兴趣的:(curl模拟登陆)