下面小編就為大家?guī)硪黄猵hp 使用curl模擬登錄人人(校內(nèi))網(wǎng)的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。
php 使用curl模擬登錄人人(校內(nèi))網(wǎng)的簡單實例
$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文件存放在網(wǎng)站根目錄的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文件,訪問人人網(wǎng)首頁
$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);
//輸出人人網(wǎng)首頁的內(nèi)容
print_r($contents);
以上這篇php 使用curl模擬登錄人人(校內(nèi))網(wǎng)的簡單實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考