PHP Demo login QQ Mailbox (Curl command detailed)

Source: Internet
Author: User
Tags set cookie
  1. Header ("Content-type:text/html;charset=utf-8");

  2. $cookie _file = dirname (__file__). " /cookie_ ". MD5 (basename (__file__)).". TXT "; Set cookie file save path and file name
  3. function Vlogin ($url, $data) {///impersonation login Get cookie functions
  4. $curl = Curl_init (); Start a Curl session
  5. curl_setopt ($curl, Curlopt_url, $url); The address to be accessed
  6. curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Examination of the source of the certification certificate
  7. curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
  8. curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
  9. curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
  10. curl_setopt ($curl, Curlopt_autoreferer, 1); Set Referer automatically
  11. curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request
  12. curl_setopt ($curl, Curlopt_postfields, $data); Post-Submitted packets
  13. curl_setopt ($curl, Curlopt_cookiejar, $GLOBALS [' cookie_file ']); File name for storing cookie information
  14. curl_setopt ($curl, Curlopt_cookiefile, $GLOBALS [' cookie_file ']); Read the cookie information stored above
  15. curl_setopt ($curl, Curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
  16. curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the header area returned
  17. curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned as a file stream
  18. $tmpInfo = curl_exec ($curl); Perform actions
  19. if (Curl_errno ($curl)) {
  20. Echo ' Errno '. Curl_error ($curl);
  21. }
  22. Curl_close ($curl); Turn off the Curl session
  23. return $tmpInfo; Return data
  24. }
  25. function Vget ($url) {//Simulate Get content function
  26. $curl = Curl_init (); Start a Curl session
  27. curl_setopt ($curl, Curlopt_url, $url); The address to be accessed
  28. curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Examination of the source of the certification certificate
  29. curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
  30. curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
  31. curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
  32. curl_setopt ($curl, Curlopt_autoreferer, 1); Set Referer automatically
  33. curl_setopt ($curl, Curlopt_httpget, 1); Send a regular POST request
  34. curl_setopt ($curl, Curlopt_cookiefile, $GLOBALS [' cookie_file ']); Read the cookie information stored above
  35. curl_setopt ($curl, Curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
  36. curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the header area returned
  37. curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned as a file stream
  38. $tmpInfo = curl_exec ($curl); Perform actions
  39. if (Curl_errno ($curl)) {
  40. Echo ' Errno '. Curl_error ($curl);
  41. }
  42. Curl_close ($curl); Turn off the Curl session
  43. return $tmpInfo; Return data
  44. }
  45. function vpost ($url, $data) {//analog commit data functions
  46. $curl = Curl_init (); Start a Curl session
  47. curl_setopt ($curl, Curlopt_url, $url); The address to be accessed
  48. curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Examination of the source of the certification certificate
  49. curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
  50. curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
  51. curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
  52. curl_setopt ($curl, Curlopt_autoreferer, 1); Set Referer automatically
  53. curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request
  54. curl_setopt ($curl, Curlopt_postfields, $data); Post-Submitted packets
  55. curl_setopt ($curl, Curlopt_cookiefile, $GLOBALS [' cookie_file ']); Read the cookie information stored above
  56. curl_setopt ($curl, Curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
  57. curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the header area returned
  58. curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned as a file stream
  59. $tmpInfo = curl_exec ($curl); Perform actions
  60. if (Curl_errno ($curl)) {
  61. Echo ' Errno '. Curl_error ($curl);
  62. }
  63. Curl_close ($curl); Critical Curl Session
  64. return $tmpInfo; Return data
  65. }

  66. function Delcookie ($cookie _file) {//delete cookie functions

  67. @unlink ($cookie _file); Perform the Delete
  68. }

  69. function Readcookies ($file)

  70. {
  71. $result = null;
  72. $fp = fopen ($file, "R");
  73. if ($FP)
  74. {
  75. while (!feof ($FP))
  76. {
  77. $buffer = Fgets ($fp, 4096);
  78. $result = $buffer;
  79. $tmp = @split ("/t", $buffer);
  80. $result [@trim ($tmp [5])] = @trim ($tmp [6]);
  81. }
  82. Fclose ($FP);
  83. }
  84. return $result;
  85. }
  86. $url = ' http://w.mail.qq.com/cgi-bin/loginpage?f=xhtml ';
  87. if (!file_exists ($cookie _file)) {//detects if a cookie exists
  88. $str = Vget ($url); Get Submit Background
  89. Preg_match ("/action=\" ([^\ "]*?) \ "/isu", $str, $hash); Extract login random values
  90. Print_r ($hash [1]);
  91. Vlogin ($hash [1], ' &f=xhtml&uin= your QQ number &aliastype= @qq. COM&PWD=QQ, Password &mss=1 '); Login to get cookies

  92. }

  93. Else
  94. {
  95. Vget ("Http://w30.mail.qq.com/cgi-bin/today?sid=ggQq2H-cUHdDdHs0z6rT6vN8,4,z-yTNgDwU&first=1");
  96. Echo ' generated a cookie ';
  97. }
  98. ?>

Copy Code

>>> More articles on PHP demo login, please refer to the topic Link: PHP Emulation login PHP Curl Demo Login Tutorial Daquan

  • Related Article

    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.