Home  >  Article  >  Backend Development  >  PHP simulates login to QQ mailbox (detailed explanation of curl command)

PHP simulates login to QQ mailbox (detailed explanation of curl command)

WBOY
WBOYOriginal
2016-07-25 09:03:561684browse
  1. header("Content-type:text/html;charset=utf-8");

  2. $cookie_file = dirname(__FILE__)."/cookie_".md5( basename(__FILE__)).".txt"; //Set the cookie file saving path and file name
  3. function vlogin($url,$data){ //Simulate login to obtain the Cookie function
  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); // Check the source of the authentication certificate
  7. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1) ; // Check whether the SSL encryption algorithm exists from the certificate
  8. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // Simulate the browser used by the user
  9. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // Use automatic redirect
  10. curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set Referer
  11. curl_setopt($curl, CURLOPT_POST, 1); // Send a regular Post request
  12. curl_setopt($curl, CURLOPT_POSTFIELDS, $data) ; // The packet submitted by Post
  13. curl_setopt($curl, CURLOPT_COOKIEJAR, $GLOBALS['cookie_file']); // The name of the file that stores Cookie information
  14. curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // Read the cookie information stored above
  15. curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set timeout limit to prevent endless loops
  16. curl_setopt($curl, CURLOPT_HEADER, 0); // Display the content of the returned Header area
  17. curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information is returned in the form of a file stream
  18. $tmpInfo = curl_exec($curl); // Execute the operation
  19. if (curl_errno($curl)) {
  20. echo 'Errno'. curl_error($curl);
  21. }
  22. curl_close($curl); // Close the CURL session
  23. return $tmpInfo; // Return data
  24. }
  25. function vget($url){ // Simulate the function of getting content
  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); // Check the source of the authentication certificate
  29. curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 1); // Check whether the SSL encryption algorithm exists from the certificate
  30. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // Simulate the browser used by the user
  31. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // Use automatic redirect
  32. curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set Referer
  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); // Set timeout limit to prevent infinite loop
  36. curl_setopt($curl, CURLOPT_HEADER, 0); // Display the content of the returned Header area
  37. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information is returned in the form of a file stream
  38. $tmpInfo = curl_exec($curl); // Execute the operation
  39. if ( curl_errno($curl)) {
  40. echo 'Errno'.curl_error($curl);
  41. }
  42. curl_close($curl); // Close CURL session
  43. return $tmpInfo; // Return data
  44. }
  45. function vpost($ url,$data){ // Simulate the submit data function
  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); // Check the source of the authentication certificate
  49. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // Check whether the SSL encryption algorithm exists from the certificate
  50. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ); // Simulate the browser used by the user
  51. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // Use automatic jump
  52. curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set the Referer
  53. curl_setopt($curl, CURLOPT_POST , 1); // Send a regular Post request
  54. curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post submitted data packet
  55. curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // Read the cookie information stored above
  56. curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set timeout limit to prevent infinite loop
  57. curl_setopt($curl, CURLOPT_HEADER, 0); // Display the content of the returned Header area
  58. curl_setopt($ curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information is returned in the form of a file stream
  59. $tmpInfo = curl_exec($curl); // Execute the operation
  60. if (curl_errno($curl)) {
  61. echo 'Errno'.curl_error( $curl);
  62. }
  63. curl_close($curl); // Key CURL session
  64. return $tmpInfo; // Return data
  65. }

  66. function delcookie($cookie_file){ // Delete Cookie Function

  67. @unlink($cookie_file); // Execute deletion
  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)) { // Check whether the cookie exists
  88. $str = vget($url); // Get the submission background
  89. preg_match("/action="([^"]*?)"/isU",$str,$hash); // Extract the login random value
  90. print_r($hash[1]);
  91. vlogin( $hash[1],'&f=xhtml&uin=your qq number&aliastype=@qq.com&pwd=qq number password&mss=1'); // Log in to get Cookie

  92. }

  93. else
  94. {
  95. vget("http://w30.mail.qq.com/cgi-bin/today?sid=ggQq2H-cUHdDdHs0z6rT6vN8,4,z-yTNgDwU&first=1");
  96. echo 'Cookie generated';
  97. }
  98. ? >

Copy code

>>> For more articles about php simulated login, please refer to the topic link: php simulated login php curl simulated login tutorial collection



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn