/**
* Demo Login
*/
//Initialize Variables
$cookie _file ="Tmp.cookie";
$login _url ="http://xxx.com/logon.php";
$verify _code_url ="http://xxx.com/verifyCode.php";
Echo"getting 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);//Get cookies and store
$contents = curl_exec ($curl);
Curl_close ($curl);
Echo"the cookie gets completed and the verification code is being taken ... \ n";
//Remove 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 is removed and is hibernating, please fill in code.txt and save \ n in 20 seconds";
//stop running for 20 seconds
Sleep -);
Echo"hibernate complete, start to fetch verification code ... \ n";
$code = file_get_contents ("Code.txt");
Echo"Verification code successfully removed: $code \ n";
Echo"Preparing for impersonation login ... \ 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 captured by your own bag to make judgments .
if(Substr_count ($result,"Login Successful")){
Echo"login successful \ n";
}Else{
Echo"Login failed \ n";
Exit
}
PHP uses curl to implement a mock login to a website with a CAPTCHA