PHP模擬登陸163郵箱發(fā)郵件及獲取通訊錄列表的方法
本文實(shí)例講述了PHP模擬登陸163郵箱發(fā)郵件及獲取通訊錄列表的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
<?php
header("Content-Type: text/html; charset=UTF-8");
error_reporting(0);
/**
* 登陸
* $user 163用戶名
* $pass 密碼
**/
function login($user,$pass){
//登陸
$url = 'http://reg.163.com/logins.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1';
$cookie = tempnam('./cache/','~');//創(chuàng)建一個(gè)用于存放cookie信息的臨時(shí)文件
$fields_post = array(
'username' => $user,
'password' => $pass,
'verifycookie' => 1,
'style' => -1,
'product' => 'mail163',
'selType' => -1,
'secure' => 'on'
);
$fields_string = '';
foreach($fields_post as $key => $value){
$fields_string .= $key . '=' . $value . '&';
}
$fields_string = rtrim($fields_string , '&');
$headers = array(
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0',
'Referer' => 'http://www.163.com'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//返回結(jié)果存放在變量中,而不是默認(rèn)的直接輸出
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);//關(guān)閉連接時(shí),將服務(wù)器端返回的cookie保存在以下文件中
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$result= curl_exec($ch);
curl_close($ch);
preg_match_all('/<div class="info" id="eHint">(.*?) <\/div>/i', $result,$infos,PREG_SET_ORDER);
if(!empty($infos['0']['1'])){
unlink($cookie);
exit('<script type="text/javascript">alert("'.$infos['0']['1'].'");history.go(-1);</script>');
}else{
$G_ROOT = dirname(__FILE__);
file_put_contents($G_ROOT.'/cache/cookie', $cookie);
return $cookie;
}
}
/**
*
* $data['url'] 請(qǐng)求地址
* $data['data_post'] post數(shù)據(jù)
* $data['cookie']
*
**/
function curl($data){
$url = $data['url'];
$data_post= $data['data_post']? $data['data_post']: false;
$cookie = $data['cookie'];
$headers = array(
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0',
'Referer' => 'http://www.163.com'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //cookie文件 登陸之后
//POST 提交
if($data_post){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_post);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
- php實(shí)現(xiàn)模擬登陸方正教務(wù)系統(tǒng)抓取課表
- PHP函數(shù)分享之curl方式取得數(shù)據(jù)、模擬登陸、POST數(shù)據(jù)
- PHP實(shí)現(xiàn)微信模擬登陸并給用戶發(fā)送消息的方法【文字,圖片,圖文】
- php模擬登陸的實(shí)現(xiàn)方法分析
- php中通過curl模擬登陸discuz論壇的實(shí)現(xiàn)代碼
- php 論壇采集程序 模擬登陸,抓取頁(yè)面 實(shí)現(xiàn)代碼
- PHP簡(jiǎn)單實(shí)現(xiàn)模擬登陸功能示例
- php實(shí)現(xiàn)微信模擬登陸、獲取用戶列表及群發(fā)消息功能示例
- PHP 模擬登陸MSN并獲得用戶信息
- php通過curl模擬登陸DZ論壇
- PHP 模擬登陸功能實(shí)例詳解
相關(guān)文章
非常好用的兩個(gè)PHP函數(shù) serialize()和unserialize()
使用serialize()函數(shù)和unserialize()函數(shù),這兩個(gè)函數(shù)的用法真是絕配,一個(gè)是進(jìn)行序列化存儲(chǔ),另一個(gè)則是進(jìn)行序列化恢復(fù),方便極了2012-02-02php下防止單引號(hào),雙引號(hào)在接受頁(yè)面轉(zhuǎn)義的設(shè)置方法
有時(shí)候我們?cè)谔砑觾?nèi)容時(shí),單引號(hào),雙引號(hào)會(huì)被轉(zhuǎn)義,用下面的方法即可解決2008-09-09php中g(shù)et_cfg_var()和ini_get()的用法及區(qū)別
這篇文章主要介紹了php中g(shù)et_cfg_var()和ini_get()的用法及區(qū)別,實(shí)例分析了get_cfg_var()和ini_get()函數(shù)的區(qū)別與使用技巧,需要的朋友可以參考下2015-03-03PHP Session ID的實(shí)現(xiàn)原理與實(shí)例
這篇文章主要介紹了PHP Session ID的實(shí)現(xiàn)原理與實(shí)例,幫助大家更好的理解和學(xué)習(xí)使用PHP,感興趣的朋友可以了解下2021-05-05PHP gbk環(huán)境下json_dencode傳送來的漢字
在做一個(gè)小項(xiàng)目的時(shí)候用得gbk,發(fā)現(xiàn)json_encode傳過來的漢子不對(duì)。搜索出結(jié)果。。留下印子不忘記。。歡迎指正2012-11-11