/**
- * @file class.qqhttp.php
- * QQ Mailbox landing Get class
- * @author WC
- * @site bbs.it-home.org
- */
Class Qqhttp {
- var $cookie = ';
- function __cunstrut () {
- }
- function Makeform () {
- $form = Array (
- ' url ' = ' http://mail.qq.com/cgi-bin/loginpage ',
- );
- $data = $this->curlfunc ($form);
- Preg_match ('/name= ' ts "\svalue=" (\d+) "/', $data [' html '], $tspre);
- $ts = $tspre [1];
- Preg_match ('/action= ' http:\/\/(m\d+) \.mail\.qq\.com/', $data [' html '], $server);
- $server _no = $server [1];
- /* login.html Loading */
- $html = file_get_contents (dirname (__file__). ' /login.htm ');
- $html = Str_replace (' {_ts_} ', $ts, $html);
- $html = Str_replace (' {_server_no_} ', $server _no, $html);
- return $html;
- }
- function Curlfunc ($array)
- {
- $ch = Curl_init ();
- curl_setopt ($ch, Curlopt_url, $array [' URL ']);
- curl_setopt ($ch, Curlopt_returntransfer, true);
- if (Isset ($array [' header ']) && $array [' header ']) {
- curl_setopt ($ch, Curlopt_header, 1);
- }
- if (Isset ($array [' Httpheader '])) {
- curl_setopt ($ch, Curlopt_httpheader, $array [' Httpheader ']);
- }
- if (Isset ($array [' Referer '])) {
- curl_setopt ($ch, Curlopt_referer, $array [' REFERER ']);
- }
- if (Isset ($array [' Post '])) {
- curl_setopt ($ch, Curlopt_post, 1);
- curl_setopt ($ch, Curlopt_postfields, $array [' Post ']);
- }
- if (Isset ($array [' Cookie ')]) {
- curl_setopt ($ch, Curlopt_cookie, $array [' COOKIE ']);
- }
- $r [' erro '] = Curl_error ($ch);
- $r [' errno '] = Curl_errno ($ch);
- $r [' html '] = curl_exec ($ch);
- $r [' http_code '] = Curl_getinfo ($ch, Curlinfo_http_code);
- Curl_close ($ch);
- return $r;
- }
- /**
- * Get Verification code pictures and cookies
- * @param Null
- *
- * @return Array (' img ' =>string, ' Cookie ' =>string)
- */
- function Getvfcode ()
- {
- $vfcode = Array (
- ' Header ' = True,
- ' Cookie ' = False,
- ' url ' = ' http://ptlogin2.qq.com/getimage?aid= '. $_get[' aid '. ' & '. @$_get[' t '],
- );
- $r = $this->curlfunc ($vfcode);
- if ($r [' http_code ']! =) return false;
- $data = Split ("\ n", $r [' html ']);
- Preg_match ('/verifysession= ([^;] +);/', $data [5], $temp);
- $cookie = Trim ($temp [1]);
- $img = $data [9];
- Return Array (' img ' = = $img, ' cookie ' = $cookie);
- }
- /**
- * Login QQ Mailbox
- *
- * @param cookies generated in the $cookie Getvfcode
- *
- * @return Array (
- * sid=>string,//user authentication unique indication
- * Login = Boolean,//true login succeeded, false login failed
- * Server_no = String//server number
- * Active = Boolean//true is open, false mailbox not opened
- * Cookie = String//Get Data cookie
- *
- * );
- */
- function Login ($cookie)
- {
- /* Generate a parameter String */
- $post = Array ();
- foreach ($_post as $k = = $v) {
- $post [] = $k. ' = '. UrlEncode ($v);
- }
- $poststr = Implode (' & ', $post);
- $r [' server_no '] = $_get[' server_no ');
- $login = Array (
- ' url ' = ' http: '/'. $r [' server_no ']. '. Mail.qq.com/cgi-bin/login?sid=0,2,zh_cn ',
- ' Header ' = True,
- ' Cookie ' = ' verifysession= '. $cookie,
- ' Referer ' = ' http://mail.qq.com/cgi-bin/loginpage ',
- ' Httpheader ' =>array (
- "Host:". $r [' Server_no ']. '. Mail.qq.com ',
- "User-agent:mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4 ",
- "Content-type:application/x-www-form-urlencoded",
- ),
- ' Post ' = $poststr,
- );
- $data = $this->curlfunc ($login);
- $data [' html '] = Iconv ("gb2312", "UTF-8", $data [' html ']);
- if ($data [' http_code ']! = 200) {
- $this->error ($data);
- return false;
- }
- /* Test Data */
- $data [' HTML '] =file_get_contents ('./r.txt ');
- $r [' uin '] = $_post[' UIn ');
- /* Login Error judgment */
- if (Preg_match (' |errtype= (\d) | ', $data [' html '], $temp _err)) {
- $r [' login '] = false;
- if ($temp _err[1] = = 1) {
- $r [' msg '] = ' account number and password error ';
- } elseif ($temp _err[1] = = 2) {
- $r [' msg '] = ' captcha error ';
- }
- return $r;
- }
- /* Login Successful */
- Preg_match (' |urlhead= ' ([^ "]+)" |i ', $data [' html '], $temp _url);
- $urlhead = $temp _url[1];
- if (Preg_match (' |frame_html\?sid= ([^ ']+) ' |i ', $data [' html '], $temp _sid)) {
- $r [' sid '] = $temp _sid[1];
- $r [' active '] = true;
- } elseif (Preg_match (' |autoactivation\?sid= ([^&]+) ' &|i ', $data [' html '], $temp _sid)) {
- $r [' sid '] = $temp _sid[1];
- $r [' active '] = false;
- }
- /* Access to cookies after login, used in subsequent operations */
- if (Preg_match_all (' | Set-cookie: ([^=]+=[^;] +) |i ', $data [' html '], $new _cookies)) {
- $cookiestr = Implode ('; ', $new _cookies[1]);
- $cookiestr. = '; Verifysession= '. $cookie;
- }
- $r [' login '] = true;
- $r [' cookie '] = $COOKIESTR;
- return $r;
- }//Bbs.it-home.org
- function Openemail ($param)
- {
- $openEmail = Array (
- ' url ' = ' http: '/'. $param [' server_no ']. '. mail.qq.com/cgi-bin/autoactivation?actmode=6&sid= '. $param [' Sid '],
- ' Header ' = True,
- ' Cookie ' = $param [' Cookie '],
- ' referer ' = ' http:/'. $param [' server_no ']. ' Mail.qq.com/cgi-bin/autoactivation?sid= '. $param [' Sid ']. ' &action=reg_activate&actmode=6 ',
- ' Httpheader ' =>array (
- "Host:". $param [' Server_no ']. '. Mail.qq.com ',
- ' accept-charset:gb2312,utf-8;q=0.7,*;q=0.7 ',
- "User-agent:mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4 ",
- ),
- );
- $data = $this->curlfunc ($openEmail);
- if (Preg_match (' | Set-cookie:qqmail_activated=0|i ', $data [' html ']) {
- $param [' active '] = true;
- $param [' cookie '] = $param [' Cookie ']. '; Qqmail_activated=0; Qqmail_alias= ';
- }
- return $param;
- }
- /**
- *
- * Get Friends Data
- *
- * @param $param = Array (
- * sid=>string,//user authentication unique indication
- * Login = Boolean,//true login succeeded, false login failed
- * Server_no = String//server number
- * Active = Boolean//true is open, false mailbox not opened
- * Cookie = String//Get Data cookie
- *
- * );
- * @return Array (
- * Key=>value,//KEY:QQ, Value:nickname
- * );
- */
- function Getfriends ($param)
- {
- $friend = Array (
- ' url ' = ' http: '/'. $param [' Server_no ']. Mail.qq.com/cgi-bin/addr_listall?type=user&&category=all&sid= '. $param [' Sid '],
- ' Header ' = True,
- ' Cookie ' = $param [' Cookie '],
- ' Referer ' = ' http://m151.mail.qq.com/cgi-bin/addr_listall?sid= '. $param [' Sid ']. ' &sorttype=null&category=common ',
- ' Httpheader ' =>array (
- "Host:". $param [' Server_no ']. '. Mail.qq.com ',
- ' accept-charset:utf-8;q=0.7,*;q=0.7 ',
- "User-agent:mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.0.9) gecko/2009040821 firefox/3.0.9 firephp/0.2.4 ",
- ),
- );
- $r = $this->curlfunc ($friend);
- if ($r [' http_code ']! = 200) {
- $this->error ($R);
- return false;
- }
- $data = $r [' html '];
- $preg = Preg_match_all (' |
]+/> ([^<]+) |i ', $data, $temp _list);
- if ($preg = = 0) return array ();
- $list = Array_combine ($temp _list[1], $temp _list[2]);
- return $list;
- }
- /**
- * ERROR Display
- *
- * @param $str Array
- *
- * @return
- */
- Function error ($STR) {
- $str [' html '] = str_replace (' script ', ' ', $str [' html ']);
- Var_dump ($STR);
- Exit
- }
- }
- ?>
Copy Code>>> more PHP Demo login articles, featured links: PHP Emulation login PHP Curl Demo Login Tutorial Daquan |