Many of the online simulation login programs, mostly through the service program Apache and other operations, get to the verification code displayed on the Web page, and then fill in and then post out, although it looks very friendly, but since the simulation login, after the log on the thing is not necessarily a short time to complete, So this is subject to PHP's maximum execution time limit, and some operations may not have enough permissions.
This article provides a program example, the idea is to obtain a verification code after the verification code stored as a picture, and then the program sleeps 20 seconds, after 20 seconds by the user manually view the picture, and to fill out the verification code To the Code.txt file, after 20 seconds of hibernation is completed, the program will read the Code.txt verification code, so that with the verification code for the login operation. The specific code is as follows:
/** * Analog Login *//Initialize variable $cookie_file = "Tmp.cookie"; $login _url = "http://xxx.com/logon.php"; $verify _code_url = "http:// Xxx.com/verifycode.php "; echo "Acquiring cookie...\n"; $CURLJ = Curl_init (); $timeout = 5;curl_setopt ($curl, Curlopt_url, $login _url); curl_setopt ($ Curl, Curlopt_returntransfer, 1); curl_setopt ($curl, Curlopt_connecttimeout, $timeout); curl_setopt ($curl, Curlopt_ Cookiejar, $cookie _file); Obtain a cookie and store $contents = curl_exec ($curl); Curl_close ($curl); echo "Cookie gets completed, retrieving verification code ... \ n";//Check out Captcha $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $verify _code_url); curl_ Setopt ($curl, Curlopt_cookiefile, $cookie _file); curl_setopt ($curl, Curlopt_header, 0); curl_setopt ($curl, Curlopt_ Returntransfer, 1); $img = Curl_exec ($curl); Curl_close ($curl); $fp = fopen ("Verifycode.jpg", "w"); Fwrite ($fp, $img); fclose ($FP); echo "Verification code out, sleeping, 20 seconds please fill in the Verification code code.txt and save \ n"; Stop running for 20 seconds Sleep (20); echo "Hibernate complete, start fetch verification code ... \ n"; $code = file_get_contents ("Code.txt"); echo "Verification code successfully removed: $code \ n"; echo "Preparing to impersonate login ... \ n"; $post = "USERNAME=MABEN&AMp;pwd=hahahaha&verifycode= $code "; $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $url); curl_setopt ($curl, Curlopt_header, False); curl_setopt ($curl, curlopt_returntransfer,1); curl_setopt ($curl, Curlopt_postfields, $post); curl_setopt ($curl, Curlopt_cookiefile, $cookie _file), $result =curl_exec ($curl); Curl_close ($curl); This piece is based on the data on the Web site captured by the package itself to determine if (Substr_count ($result, "login succeeded") {echo "Login succeeded \ n";} else{echo "Login failed \ n"; exit;//ok, start doing what you want to do ....
PHP uses curl to implement a mock login to a website with a CAPTCHA