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

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

Jul 25, 2016 am 09:03 AM

  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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles