>백엔드 개발 >PHP 튜토리얼 >php 使用curl模拟登录人人(校内)网,curl校内_PHP教程

php 使用curl模拟登录人人(校内)网,curl校内_PHP教程

WBOY
WBOY원래의
2016-07-12 08:51:21958검색

php 使用curl模拟登录人人(校内)网,curl校内

$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);

  

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1131691.htmlTechArticlephp 使用curl模拟登录人人(校内)网,curl校内 $login_url = 'http://passport.renren.com/PLogin.do';$post_fields['email'] = 'XXXX';$post_fields['password'] = 'XXXX';$post_...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.