yancoding dùng cookie là đc nhé e :D
đầu tiên vào để lấy cookie.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://forum.ngocrongonline.com/app/?for=event&do=changepass');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
lưu ảnh ở server.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://forum.ngocrongonline.com/captcha.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
file_put_contents("captcha.jpg",$result);
Tiếp theo là get captcha từ API:
$captcha = file_get_contents("https://ocr.v4u.vn/api.php?img=https://domain.com/captcha.jpg");
Giờ đến post đi nè:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://forum.ngocrongonline.com/app/?for=event&do=changepass');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=usernameoday&pass=passcuoday&npass=passoday&repass=passoday&CaptchaCode=".$captcha);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $result;