参考:http://our2848884.blog.163.com/blog/static/146854834201282039334/ php curl模拟登录
参考:http://blog.csdn.net/mingzepeng/article/details/6505955 目前最全的PHP模拟登录函数curl中文详解
$login_url = 'XXX';
$post_fields['email'] = 'XXXX';
$post_fields['password'] = 'XXXX';
$post_fields['origURL'] = 'XXX';
$post_fields['domain'] = 'xxx.com';
//cookie文件存放在网站根目录的temp文件夹下
$cookie_file = tempnam('./temp','cookie');
$ch = curl_init($login_url);// 初始化一个的curl对话
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');//为一个的curl设置对话参数
curl_setopt($ch, CURLOPT_HEADER, 0);
CURLOPT_HEADER为false,则应用CURL_TIMECOND_ISUNMODSINCE,默认 value为
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
在启用CURLOPT_RETURNTRANSFER时间将获取数据返回
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_exec($ch);
curl_close($ch);
//带上cookie文件,访问人人网首页
$send_url='xxx.com';
$ch = curl_init($send_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
//清理cookie文件
unlink($cookie_file);
//输出网页内容
print_r($contents);