CURL_模拟登录

<?php
$curl = curl_init();
$url = "http://www.imooc.com/user/login";
//$url = "http://www.imooc.com/user/newlogin/from_url/1003";
//$url = "http://www.imooc.com/space/index";
$cfile = "cookiefile";
$data = "username=*********@qq.com&password=abcdefg&remember=1";
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);	//执行的结果不直接打印
date_default_timezone_set("PRC");	//设置时区
curl_setopt($curl,CURLOPT_COOKIESESSION,true);
curl_setopt($curl,CURLOPT_COOKIEFILE,$cfile);
curl_setopt($curl,CURLOPT_COOKIEJAR,$cfile);
curl_setopt($curl,CURLOPT_COOKIE,session_name().'='.session_id());
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
$res = curl_exec($curl);
echo $res;
exit();
$url2 = "http://www.imooc.com/space/index";
curl_setopt($curl,CURLOPT_URL,$url2);
curl_setopt($curl,CURLOPT_POST,0);
$oput = curl_exec($curl);
echo $oput;
curl_close($curl);
?>

 

posted @ 2014-06-21 18:08  半颠者  阅读(324)  评论(0编辑  收藏  举报