php 应用curl模仿登录人人(校内)网
添加时间:2013-7-23 点击量:
¥login_url = http://passport.renren.com/PLogin.do;
¥post_fields[email] = XXXX;
¥post_fields[password] = XXXX;
¥post_fields[origURL] = http%3A%2F%2Fhome.renren.com%2FHome.do;
¥post_fields[domain] = renren.com;
//cookie文件存放在网站根目次的temp文件夹下
¥cookie_file = tempnam(./temp,cookie);
¥ch = curl_init(¥login_url);
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_setopt(¥ch, CURLOPT_HEADER, 0);
curl_setopt(¥ch, CURLOPT_RETURNTRANSFER, 1);
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_setopt(¥ch, CURLOPT_COOKIEJAR, ¥cookie_file);
curl_exec(¥ch);
curl_close(¥ch);
//带上cookie文件,接见人人网首页
¥send_url=http://home.renren.com/Home.do;
¥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);
文艺不是炫耀,不是花哨空洞的文字堆砌,不是一张又一张的逆光照片,不是将旅行的意义转化为名牌包和明信片的物质展示;很多时候它甚至完全不美——它嘶吼、扭曲,它会痛苦地抽搐,它常常无言地沉默。——艾小柯《文艺是一种信仰》
¥login_url = http://passport.renren.com/PLogin.do;
¥post_fields[email] = XXXX;
¥post_fields[password] = XXXX;
¥post_fields[origURL] = http%3A%2F%2Fhome.renren.com%2FHome.do;
¥post_fields[domain] = renren.com;
//cookie文件存放在网站根目次的temp文件夹下
¥cookie_file = tempnam(./temp,cookie);
¥ch = curl_init(¥login_url);
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_setopt(¥ch, CURLOPT_HEADER, 0);
curl_setopt(¥ch, CURLOPT_RETURNTRANSFER, 1);
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_setopt(¥ch, CURLOPT_COOKIEJAR, ¥cookie_file);
curl_exec(¥ch);
curl_close(¥ch);
//带上cookie文件,接见人人网首页
¥send_url=http://home.renren.com/Home.do;
¥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);