码迷,mamicode.com
首页 > Web开发 > 详细

curl模拟登录

时间:2015-08-02 13:15:04      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

$post_data = array("username"=>"yuejide@163.com","password"=>"yuejide198225","remember"=>0); 
$data = http_build_query($post_data); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://www.imooc.com/user/login"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//不要直接输出 

date_default_timezone_set(‘PRC‘); 
curl_setopt($ch, CURLOPT_COOKIESESSION,1); 
curl_setopt($ch, CURLOPT_COOKIEFILE,"cookiefile"); 
curl_setopt($ch, CURLOPT_COOKIEJAR,"cookiefile"); 
curl_setopt($ch, CURLOPT_COOKIE,session_name().‘=‘.session_id()); 
curl_setopt($ch, CURLOPT_HEADER,0); 
//这样设置能够让curl支持页面跳转 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); 
curl_setopt($ch, CURLOPT_POST,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_HTTPHEADER,array("application/x-www-form-urlencoded;charset=utf8","Content-length:".strlen($data))); 
curl_exec($ch);//执行 
curl_setopt($ch, CURLOPT_URL, "http://www.imooc.com/space/index"); 
curl_setopt($ch, CURLOPT_POST,0); 
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-type:text/html")); 
$output = curl_exec($ch); 
curl_close($ch); 
//打印数据 
echo $output;

 

curl模拟登录

标签:

原文地址:http://www.cnblogs.com/gide/p/4695522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!