Many of the online analog login procedures, mostly through the service program, such as Apache operation, get to the verification code displayed on the Web page, and then fill in the post out, so although it looks very friendly, but since the analog login, the things that do after login is not necessarily a short time to complete, So this is subject to PHP's maximum execution time limit, and some operations may have insufficient permissions.
This article provides an example of a program, the idea is to obtain the verification code after the code stored as a picture, and then the program hibernate 20 seconds, 20 seconds after the user manually view the picture, and the verification code to fill in the Code.txt file, 20 seconds after hibernation, the program will read the Code.txt code, so again with the verification code for the login operation. The specific code is as follows:
/** * Analog Login///initialization variable $cookie _file = "Tmp.cookie";
$login _url = "http://xxx.com/logon.php";
$verify _code_url = "http://xxx.com/verifyCode.php";
echo "is 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);
Gets the cookie and stores the $contents = Curl_exec ($curl);
Curl_close ($curl);
echo "Cookie fetch complete, fetching captcha ... \ n";
Remove the verification code $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, is sleeping, within 20 seconds, please fill in the Code.txt and save \ n";
Stop running for 20 seconds Sleep (20);
echo "Hibernate complete, start fetching captcha ... \ n";
$code = file_get_contents ("Code.txt");
echo "Verification code successfully removed: $code \ n"; ECHO is preparing the impersonationLogin ... \ 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 piece is based on the data on the Web site that you grabbed to get it. if (Substr_count ($result, "login succeeded") {echo "logon succeeded \ n";}
else{echo "Login failed \ n";
Exit
//ok, start doing what you want to do ...