Header ("Content-type:text/html;charset=utf-8");
- $cookie _file = dirname (__file__). " /cookie_ ". MD5 (basename (__file__)).". TXT "; Set cookie file save path and file name
- function Vlogin ($url, $data) {///impersonation login Get cookie functions
- $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); Examination of the source of the certification certificate
- curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
- curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
- curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
- curl_setopt ($curl, Curlopt_autoreferer, 1); Set Referer automatically
- curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request
- curl_setopt ($curl, Curlopt_postfields, $data); Post-Submitted packets
- curl_setopt ($curl, Curlopt_cookiejar, $GLOBALS [' cookie_file ']); File name for storing cookie information
- curl_setopt ($curl, Curlopt_cookiefile, $GLOBALS [' cookie_file ']); Read the cookie information stored above
- curl_setopt ($curl, Curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
- curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the header area returned
- curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned as a file stream
- $tmpInfo = curl_exec ($curl); Perform actions
- if (Curl_errno ($curl)) {
- Echo ' Errno '. Curl_error ($curl);
- }
- Curl_close ($curl); Turn off the Curl session
- return $tmpInfo; Return data
- }
- function Vget ($url) {//Simulate Get content 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); Examination of the source of the certification certificate
- curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
- curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
- curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
- curl_setopt ($curl, Curlopt_autoreferer, 1); Set Referer automatically
- 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); Setting a timeout limit to prevent a dead loop
- curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the header area returned
- curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned as a file stream
- $tmpInfo = curl_exec ($curl); Perform actions
- if (Curl_errno ($curl)) {
- Echo ' Errno '. Curl_error ($curl);
- }
- Curl_close ($curl); Turn off the Curl session
- return $tmpInfo; Return data
- }
- function vpost ($url, $data) {//analog commit data functions
- $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); Examination of the source of the certification certificate
- curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
- curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
- curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
- curl_setopt ($curl, Curlopt_autoreferer, 1); Set Referer automatically
- curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request
- curl_setopt ($curl, Curlopt_postfields, $data); Post-Submitted packets
- curl_setopt ($curl, Curlopt_cookiefile, $GLOBALS [' cookie_file ']); Read the cookie information stored above
- curl_setopt ($curl, Curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
- curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the header area returned
- curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned as a file stream
- $tmpInfo = curl_exec ($curl); Perform actions
- if (Curl_errno ($curl)) {
- Echo ' Errno '. Curl_error ($curl);
- }
- Curl_close ($curl); Critical Curl Session
- return $tmpInfo; Return data
- }
function Delcookie ($cookie _file) {//delete cookie functions
- @unlink ($cookie _file); Perform the Delete
- }
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)) {//detects if a cookie exists
- $str = Vget ($url); Get Submit Background
- Preg_match ("/action=\" ([^\ "]*?) \ "/isu", $str, $hash); Extract login random values
- Print_r ($hash [1]);
- Vlogin ($hash [1], ' &f=xhtml&uin= your QQ number &aliastype= @qq. COM&PWD=QQ, Password &mss=1 '); Login to get cookies
}
- Else
- {
- Vget ("Http://w30.mail.qq.com/cgi-bin/today?sid=ggQq2H-cUHdDdHs0z6rT6vN8,4,z-yTNgDwU&first=1");
- Echo ' generated a cookie ';
- }
- ?>
Copy Code>>> More articles on PHP demo login, please refer to the topic Link: PHP Emulation login PHP Curl Demo Login Tutorial Daquan |