-
-
header("Content-type:text/html;charset=utf-8"); - $cookie_file = dirname(__FILE__)."/cookie_".md5( basename(__FILE__)).".txt"; //Set the cookie file saving path and file name
- function vlogin($url,$data){ //Simulate login to obtain the Cookie function
- $curl = curl_init(); // Start A CURL session
- curl_setopt($curl, CURLOPT_URL, $url); // The address to be accessed
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Check the source of the authentication certificate
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1) ; // Check whether the SSL encryption algorithm exists from the certificate
- curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // Simulate the browser used by the user
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // Use automatic redirect
- curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set Referer
- curl_setopt($curl, CURLOPT_POST, 1); // Send a regular Post request
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data) ; // The packet submitted by Post
- curl_setopt($curl, CURLOPT_COOKIEJAR, $GLOBALS['cookie_file']); // The name of the file that stores Cookie information
- curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // Read the cookie information stored above
- curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set timeout limit to prevent endless loops
- curl_setopt($curl, CURLOPT_HEADER, 0); // Display the content of the returned Header area
- curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information is returned in the form of a file stream
- $tmpInfo = curl_exec($curl); // Execute the operation
- if (curl_errno($curl)) {
- echo 'Errno'. curl_error($curl);
- }
- curl_close($curl); // Close the CURL session
- return $tmpInfo; // Return data
- }
-
- function vget($url){ // Simulate the function of getting content
- $curl = curl_init(); // Start a CURL session
- curl_setopt($curl, CURLOPT_URL, $url); // The address to be accessed
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Check the source of the authentication certificate
- curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 1); // Check whether the SSL encryption algorithm exists from the certificate
- curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // Simulate the browser used by the user
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // Use automatic redirect
- curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set Referer
- curl_setopt($curl, CURLOPT_HTTPGET, 1); // Send a regular Post request
- curl_setopt($ curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // Read the cookie information stored above
- curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set timeout limit to prevent infinite loop
- curl_setopt($curl, CURLOPT_HEADER, 0); // Display the content of the returned Header area
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information is returned in the form of a file stream
- $tmpInfo = curl_exec($curl); // Execute the operation
- if ( curl_errno($curl)) {
- echo 'Errno'.curl_error($curl);
- }
- curl_close($curl); // Close CURL session
- return $tmpInfo; // Return data
- }
-
- function vpost($ url,$data){ // Simulate the submit data function
- $curl = curl_init(); // Start a CURL session
- curl_setopt($curl, CURLOPT_URL, $url); // The address to be accessed
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Check the source of the authentication certificate
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // Check whether the SSL encryption algorithm exists from the certificate
- curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ); // Simulate the browser used by the user
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // Use automatic jump
- curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // Automatically set the Referer
- curl_setopt($curl, CURLOPT_POST , 1); // Send a regular Post request
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post submitted data packet
- curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // Read the cookie information stored above
- curl_setopt($curl, CURLOPT_TIMEOUT, 30); // Set timeout limit to prevent infinite loop
- curl_setopt($curl, CURLOPT_HEADER, 0); // Display the content of the returned Header area
- curl_setopt($ curl, CURLOPT_RETURNTRANSFER, 1); // The obtained information is returned in the form of a file stream
- $tmpInfo = curl_exec($curl); // Execute the operation
- if (curl_errno($curl)) {
- echo 'Errno'.curl_error( $curl);
- }
- curl_close($curl); // Key CURL session
- return $tmpInfo; // Return data
- }
function delcookie($cookie_file){ // Delete Cookie Function
- @unlink($cookie_file); // Execute deletion
- }
function readcookies( $file)
- {
- $result = null;
-
- $fp = fopen( $file, "r" );
- if($fp)
- {
- while ( !feof( $fp ) )
- {
- $buffer = fgets( $fp, 4096 );
- $result = $buffer;
- //$tmp = @split( "/t", $buffer );
- //$ result[@trim( $tmp[5] )] = @trim( $tmp[6] );
- }
-
- fclose($fp);
- }
-
- return $result;
- }
- $url = 'http: //w.mail.qq.com/cgi-bin/loginpage?f=xhtml';
- if(!file_exists($cookie_file)) { // Check whether the cookie exists
- $str = vget($url); // Get the submission background
- preg_match("/action="([^"]*?)"/isU",$str,$hash); // Extract the login random value
- print_r($hash[1]);
- vlogin( $hash[1],'&f=xhtml&uin=your qq number&aliastype=@qq.com&pwd=qq number password&mss=1'); // Log in to get Cookie
}
- else
- {
- vget("http://w30.mail.qq.com/cgi-bin/today?sid=ggQq2H-cUHdDdHs0z6rT6vN8,4,z-yTNgDwU&first=1");
- echo 'Cookie generated';
- }
- ? >
Copy code
>>> For more articles about php simulated login, please refer to the topic link: php simulated login php curl simulated login tutorial collection
|