// Initialize the variable $ Cookie_file = "tmp. cookie "; $ Login_url = "http://xxx.com/logon.php "; $ Verify_code_url = "http://xxx.com/verifyCode.php "; Echo "obtaining 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 and store the COOKIE $ Contents = curl_exec ($ curl ); Curl_close ($ curl ); Echo "the COOKIE is obtained. The verification code... n is being obtained "; // Retrieve the verification code www.111cn.net $ 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 "the verification code has been obtained and is waiting for a sleep. Please enter the verification code in code.txt within 20 seconds and save n "; // Stops running for 20 seconds Sleep (20 ); Echo "sleep complete, start to get the verification code... n "; $ Code = file_get_contents ("code.txt "); Echo "the verification code is successfully retrieved: $ coden "; Echo "preparing to simulate logon... n "; $ Post = "username = maben & 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 part is determined based on the data on the website obtained through the packet capture. If (substr_count ($ result, "logon successful ")){ Echo "logon successful n "; } Else { Echo "logon failed n "; Exit; } // La, start doing what you want to do ..... |