PHP Analog Login 163 email and get address list method _php Tips

Source: Internet
Author: User

This article describes the PHP simulation landing 163 mailbox Email and get address list of methods. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:

<?php
Header ("content-type:text/html; Charset=utf-8 ");
error_reporting (0);
/**
* Landing
* $user 163 User Name
* $pass Password
**/
function login ($user, $pass) {
Landing
$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/', ' ~ ');//Create a temporary file for storing cookie information
$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);//Returns the result is stored in the variable instead of the default direct output
curl_setopt ($ch, Curlopt_header, true);
curl_setopt ($ch, Curlopt_connecttimeout, 120);
curl_setopt ($ch, Curlopt_httpheader, $headers);
curl_setopt ($ch, Curlopt_cookiejar, $cookie);//When closing a connection, save the cookie returned on the server side in the following file
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 '] request address
* $data [' data_post '] post data
* $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); After the cookie file is logged in
POST Submit
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;
}

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.