Hello,
I want to Login to website (there is address in the code below) with cURL and DeathByCaptcha, but when ro run this code I faced by messgae: Incorrect Captcha!
If anybody knows my problem please help. Thanks
I write this following code:
I want to Login to website (there is address in the code below) with cURL and DeathByCaptcha, but when ro run this code I faced by messgae: Incorrect Captcha!
If anybody knows my problem please help. Thanks
I write this following code:
PHP:
<?php
require_once ('deathbycaptcha.class.php'); //www.deathbycaptcha.com - github.com/Yanikore
require_once ('simple_html_dom.php'); //Website: http://sourceforge.net/projects/simplehtmldom/
$webiste = 'https://ais.usvisa-info.com/en-ae/niv/users/sign_in';
$html = file_get_html($webiste);
foreach($html->find('input[name=authenticity_token]') as $element)
$authenticity_token = $element->value;
$recaptcha = 'http://www.google.com/recaptcha/api/noscript?k=6LeUjCcTAAAAADtvVaUpCp7vy6hLk73NT6zaHZos';
$html = file_get_html($recaptcha);
foreach($html->find('input[name=recaptcha_challenge_field]') as $element)
$recaptcha_challenge_field = $element->value;
foreach($html->find('img') as $element)
$recaptcha_src = $element->src;
$uniqid = 'captcha.png';
$ch = curl_init('http://www.google.com/recaptcha/api/'.$recaptcha_src.'');
$fp = fopen($uniqid, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept-Encoding: gzip, deflate, sdch'
));
curl_exec($ch);
curl_close($ch);
fclose($fp);
try {
$dbc = new DeathByCaptcha('MyUser', 'MyPass');
if($dbc->getBalance() > 0){
if($dbc->setCaptchaFromImage($uniqid)){
if($dbc->submitCaptcha()){
$recaptcha_response_field = $dbc->getCaptchaText();
}
}
}
} catch(Exception $ex) {
echo "<pre>$ex</pre>";
}
define('COOKIE', './cookie.txt');
define('MYURL', 'https://ais.usvisa-info.com/en-ae/niv/users/sign_in');
function getUrl($url, $method='', $vars='', $open=false) {
static $cookie = false;
if (!$cookie) {
$cookie = session_name() . '=' . time();
}
$referer = 'https://ais.usvisa-info.com/en-ae/niv/users/sign_in';
$ch = curl_init();
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$vars");
}
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 5);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem");
$request_headers = array();
$request_headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36';
$request_headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$request_headers[] = 'Cookie: '.$cookie.'';
$request_headers[] = 'Accept-Encoding: gzip, deflate';
$request_headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
$request_headers[] = 'Accept-Language: en-US,en;q=0.8';
$request_headers[] = 'Host: ais.usvisa-info.com';
$request_headers[] = 'Origin: https://ais.usvisa-info.com';
$request_headers[] = 'Content-Type: application/x-www-form-urlencoded';
$request_headers[] = 'Upgrade-Insecure-Requests: 1';
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$buffer = curl_exec($ch);
if (curl_errno($ch)) {
echo "error " . curl_error($ch);
die;
}
curl_close($ch);
return $buffer;
}
echo getUrl('https://ais.usvisa-info.com/en-ae/niv/users/sign_in', 'post', 'utf8=?&authenticity_token='.$authenticity_token.'&user[email][email protected]&user[password]=12345&recaptcha_challenge_field='.$recaptcha_challenge_field.'&recaptcha_response_field='.$recaptcha_response_field.'&commit=Sing In');
?>