PHP Access 163, Sina, Sohu, Yahoo, 126, Gmail, Tom mailbox contact address

Source: Internet
Author: User
  1. <?php
  2. /**
  3. * @file class.126http.php
  4. * Get 126 Email address List
  5. * @author jvones<jvones@gmail.com> Http://www.jvones.com/blog
  6. * @date 2009-09-26
  7. **/
  8. Class http126
  9. {
  10. Private Function Login ($username, $password)
  11. {
  12. First step: initial landing
  13. $cookies = Array ();
  14. $ch = Curl_init ();
  15. curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
  16. 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%26lightweight%3d1%26verifycookie%3d1%26language%3d0%26style% 3d-1 ");
  17. curl_setopt ($ch, Curlopt_post, 1);
  18. curl_setopt ($ch, Curlopt_postfields, "username=". $username. " @126.com&password= ". $password);
  19. curl_setopt ($ch, Curlopt_cookiejar, Cookiejar);
  20. curl_setopt ($ch, curlopt_header,1);
  21. curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
  22. curl_setopt ($ch, Curlopt_returntransfer, true);
  23. $str = curl_exec ($ch);
  24. File_put_contents ('./126result.txt ', $str);
  25. Curl_close ($ch);
  26. Gets the Redirect_url jump address, which can be viewed from the 126result.txt, matching the address in the $str return stream by a regular
  27. Preg_match ("/replace (. *)");/", $str, $mtitle);
  28. $_URL1 = $mtitle [1];
  29. File_put_contents ('./126resulturl.txt ', $redirect _url);
  30. Step two: Jump again to the top $_URL1
  31. $ch = Curl_init ($_URL1);
  32. curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
  33. curl_setopt ($ch, Curlopt_returntransfer, true);
  34. curl_setopt ($ch, Curlopt_cookiefile,cookiejar);
  35. curl_setopt ($ch, Curlopt_cookiejar, Cookiejar);
  36. curl_setopt ($ch, curlopt_header,1);
  37. $str 2 = curl_exec ($ch);
  38. Curl_close ($ch);
  39. if (Strpos ($contents, "safe exit")!== false)
  40. {
  41. return 0;
  42. }
  43. return 1;
  44. }
  45. /**
  46. * Get mail Address Book-Addresses
  47. * @param $user
  48. * @param $password
  49. * @param $result
  50. * @return Array
  51. */
  52. Public Function Getaddresslist ($username, $password)
  53. {
  54. if (! $this->login ($username, $password))
  55. {
  56. return 0;
  57. }
  58. $header = $this->_getheader ($username);
  59. if (! $header [' Sid '])
  60. {
  61. return 0;
  62. }
  63. Test to find SID (very important) and host
  64. File_put_contents ('./host.txt ', $header [' Host ']);
  65. File_put_contents ('./sid.txt ', $header [' Sid ']);
  66. Start into the simulation crawl
  67. $ch = Curl_init ();
  68. curl_setopt ($ch, Curlopt_url, "http://". $header [' Host ']. " /a/s?sid= ". $header [' Sid ']." &func=global:sequential ");
  69. curl_setopt ($ch, Curlopt_cookiefile, Cookiejar);
  70. curl_setopt ($ch, Curlopt_httpheader, Array ("Content-type:application/xml"));
  71. $str = "<?xml version=" 1.0 "><object><array name=" items "><object><string name=" func "> Pab:searchcontacts</string><object name= "var" ><array name= "order" ><object><string name = "Field" >fn</string><boolean name= "IgnoreCase" >true</boolean></object></array> </object></object><object><string name= "func" >user:getsignatures</string></ Object><object><string name= "func" >pab:getAllGroups</string></object></array> </object> ";
  72. curl_setopt ($ch, Curlopt_post, 1);
  73. curl_setopt ($ch, Curlopt_postfields, $STR);
  74. curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
  75. Ob_start ();
  76. Curl_exec ($ch);
  77. $contents = Ob_get_contents ();
  78. Ob_end_clean ();
  79. Curl_close ($ch);
  80. Get mail list from the page information username && emailaddress
  81. Preg_match_all ("/<strings*name=" EMAIL; Pref "> (. *) </string>/umsi", $contents, $mails);
  82. Preg_match_all ("/<strings*name=" FN "> (. *) </string>/umsi", $contents, $names);
  83. $users = Array ();
  84. foreach ($names [1] as $k => $user)
  85. {
  86. $user = Iconv ($user, ' utf-8 ', ' gb2312 ');
  87. $users [$mails [1][$k]] = $user;
  88. }
  89. if (! $users)
  90. {
  91. Return ' no contact in your mailbox ';
  92. }
  93. return $users;
  94. }
  95. /**
  96. * Get Header Info
  97. */
  98. Private Function _getheader ($username)
  99. {
  100. $ch = Curl_init ();
  101. 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 ");
  102. curl_setopt ($ch, Curlopt_cookiefile, Cookiejar); Cookies currently in use
  103. curl_setopt ($ch, Curlopt_cookiejar, Cookiejar); New cookies returned by the server
  104. curl_setopt ($ch, Curlopt_returntransfer, true);
  105. curl_setopt ($ch, Curlopt_header, true);
  106. curl_setopt ($ch, Curlopt_nobody, true);
  107. $content =curl_exec ($ch);
  108. Preg_match_all ('/location:s* (. *?) Rn/i ', $content, $regs);
  109. $refer = $regs [1][0];
  110. Preg_match_all ('/http://(. *?) I ', $refer, $regs);
  111. $host = $regs [1][0];
  112. Preg_match_all ("/sid= (. *)/I", $refer, $regs);
  113. $sid = $regs [1][0];
  114. Curl_close ($ch);
  115. Return Array (' SID ' => $sid, ' refer ' => $refer, ' host ' => $host);
  116. }
  117. }
  118. ?>

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.