function CheckCaptchaError($data){
# Your client has issued a malformed or illegal request.
if(preg_match('/To protect our users/s',$data)) die("\nOOOOOps... To protect our users, we can't process your request right now.");
preg_match('/<img src="(\/sorry\/image\?id=\d+)/s',$data,$err);
if($captcha=$err[1]){
$cimg=$this->curl->fetch_url($this->init_url.$captcha);
if(!$cimg) die('Cant get captcha');
$capf=fopen($this->capFile,'w');
flock($capf,LOCK_EX);
fwrite($capf,$cimg);
fclose($capf);
$capanswer=fopen($this->capAnswerFile,'w');
fclose($capanswer);
while(!$answer=file_get_contents($this->capAnswerFile)){
echo "Waiting for captcha answer... Sleeping 5 sec.\n";flush();ob_flush();
sleep(5);
}
//got answer, so post it
preg_match('/name="continue" value="(.*?)">/s',$data,$cont); $cont=$cont[1];
preg_match('/name="id" value="(.*?)">/s',$data,$id); $id=$id[1];
$result=$this->curl->fetch_url($this->init_url.'/sorry/Captcha?id='.$id."&continue=$cont&captcha=$answer");
if(!$result) die('Cant send captcha');
$this->CheckCaptchaError($result);
preg_match('/content="1; url=(.*?)"/s',$result,$urlto);$urlto=$urlto[1];
if(file_exists($this->capAnswerFile))unlink($this->capAnswerFile);
if(file_exists($this->capFile))unlink($this->capFile);
return $this->curl->fetch_url($urlto);
}
return $data;
}