PHP obtains the contact addresses of 163, sina, sohu, yahoo, 126, gmail, and tom email.-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? Php *** @ fileclass.126http. php * Get 126 mail address book list * @ authorjvones & lt; jvones@gmail.com & gt; www. jvones. comblog * @ date2009-09-26 ** & nbsp; "script" ec (2); "script"

  1. /**
  2. * @ File class.126http. php
  3. * Obtain the 126 email address book list
  4. * @ Author jvones Http://www.jvones.com/blog
  5. * @ Date 2009-09-26
  6. **/
  7. Class http126
  8. {
  9. Private function login ($ username, $ password)
  10. {
  11. // Step 1: initial login
  12. $ Cookies = array ();
  13. $ Ch = curl_init ();
  14. Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false );
  15. Curl_setopt ($ ch, CURLOPT_URL, "https://reg.163.com/logins.jsp? Type = 1 & product = mail126 & url = http://entry.mail.126.com/cgi/ntesdoor? Hid % 3D10010102% 26 lightweight % 3D1% 26 verifycookie % 3D1% 26 language % 3D0% 26 style % 3D-1 ");
  16. Curl_setopt ($ ch, CURLOPT_POST, 1 );
  17. Curl_setopt ($ ch, CURLOPT_POSTFIELDS, "username =". $ username. "@ 126.com& password =". $ password );
  18. Curl_setopt ($ ch, CURLOPT_COOKIEJAR, COOKIEJAR );
  19. Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
  20. Curl_setopt ($ ch, CURLOPT_TIMEOUT, TIMEOUT );
  21. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
  22. $ Str = curl_exec ($ ch );
  23. // File_put_contents ('./126result.txt', $ str );
  24. Curl_close ($ ch );
  25. // Obtain the redirect_url.pdf address, which can be viewed from 126result.txt and matched in the $ str returned stream using the regular expression.
  26. Preg_match ("/replace ("(.*?) ");/", $ Str, $ mtitle );
  27. $ _ Url1 = $ mtitle [1];
  28. // File_put_contents ('./126resulturl.txt', $ redirect_url );
  29. // Step 2: Jump to $ _ url1
  30. $ Ch = curl_init ($ _ url1 );
  31. Curl_setopt ($ ch, CURLOPT_TIMEOUT, TIMEOUT );
  32. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
  33. Curl_setopt ($ ch, CURLOPT_COOKIEFILE, COOKIEJAR );
  34. Curl_setopt ($ ch, CURLOPT_COOKIEJAR, COOKIEJAR );
  35. Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
  36. $ Str2 = curl_exec ($ ch );
  37. Curl_close ($ ch );
  38. If (strpos ($ contents, "exit safely ")! = False)
  39. {
  40. Return 0;
  41. }
  42. Return 1;
  43. }
  44. /**
  45. * Get the email address book-address
  46. * @ Param $ user
  47. * @ Param $ password
  48. * @ Param $ result
  49. * @ Return array
  50. */
  51. Public function getAddressList ($ username, $ password)
  52. {
  53. If (! $ This-> login ($ username, $ password ))
  54. {
  55. Return 0;
  56. }
  57. $ Header = $ this-> _ getheader ($ username );
  58. If (! $ Header ['sid '])
  59. {
  60. Return 0;
  61. }
  62. // Locate the sid (important) and host in the test
  63. // File_put_contents ('./host.txt', $ header ['host']);
  64. // File_put_contents ('./sid.txt', $ header ['sid ']);
  65. // Start to enter the simulated capture
  66. $ Ch = curl_init ();
  67. Curl_setopt ($ ch, CURLOPT_URL, "http: //". $ header ['host']. "/a/s? Sid = ". $ header ['sid ']." & func = global: sequential ");
  68. Curl_setopt ($ ch, CURLOPT_COOKIEFILE, COOKIEJAR );
  69. Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/xml "));
  70. $ Str =" Pab: searchContacts FN True User: getSignatures Pab: getAllGroups ";
  71. Curl_setopt ($ ch, CURLOPT_POST, 1 );
  72. Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ str );
  73. Curl_setopt ($ ch, CURLOPT_TIMEOUT, TIMEOUT );
  74. Ob_start ();
  75. Curl_exec ($ ch );
  76. $ Contents = ob_get_contents ();
  77. Ob_end_clean ();
  78. Curl_close ($ ch );
  79. // Get mail list from the page information username & emailaddress
  80. Preg_match_all ("/ (.*)/Umsi ", $ contents, $ mails );
  81. Preg_match_all ("/ (.*)/Umsi ", $ contents, $ names );
  82. $ Users = array ();
  83. Foreach ($ names [1] as $ k => $ user)
  84. {
  85. // $ User = iconv ($ user, 'utf-8', 'gb2312 ');
  86. $ Users [$ mails [1] [$ k] = $ user;
  87. }
  88. If (! $ Users)
  89. {
  90. Return 'no contacts in your mailbox ';
  91. }
  92. Return $ users;
  93. }
  94. /**
  95. * Get Header info
  96. */
  97. Private function _ getheader ($ username)
  98. {
  99. $ Ch = curl_init ();
  100. Curl_setopt ($ ch, CURLOPT_URL, "http://entry.mail.126.com/cgi/ntesdoor? Hid = 10010102 & lightweight = 1 & verifycookie = 1 & language = 0 & style =-1 & username = ". $ username." @ 126.com ");
  101. Curl_setopt ($ ch, CURLOPT_COOKIEFILE, COOKIEJAR); // The cookie currently in use
  102. Curl_setopt ($ ch, CURLOPT_COOKIEJAR, COOKIEJAR); // The new cookie returned by the server
  103. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
  104. Curl_setopt ($ ch, CURLOPT_HEADER, true );
  105. Curl_setopt ($ ch, CURLOPT_NOBODY, true );
  106. $ Content = curl_exec ($ ch );
  107. Preg_match_all ('/Location: s *(.*?) Rn/I ', $ content, $ regs );
  108. $ Refer = $ regs [1] [0];
  109. Preg_match_all ('/http ://(.*?) // I ', $ refer, $ regs );
  110. $ Host = $ regs [1] [0];
  111. Preg_match_all ("/sid = (. *)/I", $ refer, $ regs );
  112. $ Sid = $ regs [1] [0];
  113. Curl_close ($ ch );
  114. Return array ('sid '=> $ sid, 'Referer' => $ refer, 'host' => $ host );
  115. }
  116. }
  117. ?>

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.