当前位置:Gxlcms > PHP教程 > curl模拟登陆总是弹出验证码不正确

curl模拟登陆总是弹出验证码不正确

时间:2021-07-01 10:21:17 帮助过:19人阅读

header("Content-type: text/html; charset=gb2312");
$CookieFile=tempnam("./tmep","beast");
if(isset($_GET["img"])){
$url = 'http://jwc.wyu.edu.cn/student/rndnum.asp';//验证码code
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);//把返回来的cookie信息保存在文件中
curl_exec($ch);
curl_close($ch);
exit();
}
if(isset($_POST['d'])){
$b=$_POST['d'];//验证码
$p="UserCode=3114002555&UserPwd=不告诉你&Validate=".$b."&Submit=提 交";
$ch = curl_init();
// 2. 设置选项,包括URL
$reffer = 'http://jwc.wyu.edu.cn/student/body.htm';
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
curl_setopt($ch,CURLOPT_URL, "http://jwc.wyu.edu.cn/student/logon.asp");
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);
curl_setopt($ch,CURLOPT_COOKIEFILE, $CookieFile);//同时发送Cookie
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $p);//提交查询信息
$s = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
$reffer = 'http://jwc.wyu.edu.cn/student/body.htm';
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
curl_setopt($ch,CURLOPT_URL, "http://jwc.wyu.edu.cn/student/logon.asp");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_COOKIEFILE, $CookieFile);//同时发送Cookie
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $p);//提交查询信息
$bs = curl_exec($ch);
echo $bs;//输出结果
curl_close($ch);
}else{
?>

}
?>


回复讨论(解决方案)

$url = 'http://jwc.wyu.edu.cn/student/';print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Connection: close
[3] => Date: Mon, 24 Aug 2015 11:30:29 GMT
[4] => Content-Length: 617
[5] => Content-Type: text/html
[6] => Set-Cookie: ASPSESSIONIDCQAATSAR=HGOCKONAKIMOPBIOFJFHPGFI; path=/
[7] => Server: IIS
[8] => X-Powered-By: WAF/2.0
[9] => Set-Cookie: safedog-flow-item=6BFDB3BC0A21C98B7224B81C2C04C934; expires=Mon, 24-Aug-2015 16:00:29 GMT; domain=wyu.edu.cn; path=/
)
访问主页就已经有 session 了,你读验证码时不带上是不行的

怎么带上session,在哪里带上

$url = 'http://jwc.wyu.edu.cn/student/';print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Connection: close
[3] => Date: Mon, 24 Aug 2015 11:30:29 GMT
[4] => Content-Length: 617
[5] => Content-Type: text/html
[6] => Set-Cookie: ASPSESSIONIDCQAATSAR=HGOCKONAKIMOPBIOFJFHPGFI; path=/
[7] => Server: IIS
[8] => X-Powered-By: WAF/2.0
[9] => Set-Cookie: safedog-flow-item=6BFDB3BC0A21C98B7224B81C2C04C934; expires=Mon, 24-Aug-2015 16:00:29 GMT; domain=wyu.edu.cn; path=/
)
访问主页就已经有 session 了,你读验证码时不带上是不行的



怎么带上 我学没多久,curl弄了很久了 如果可以能告诉下吗

$url = 'http://jwc.wyu.edu.cn/student/';print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Connection: close
[3] => Date: Mon, 24 Aug 2015 11:30:29 GMT
[4] => Content-Length: 617
[5] => Content-Type: text/html
[6] => Set-Cookie: ASPSESSIONIDCQAATSAR=HGOCKONAKIMOPBIOFJFHPGFI; path=/
[7] => Server: IIS
[8] => X-Powered-By: WAF/2.0
[9] => Set-Cookie: safedog-flow-item=6BFDB3BC0A21C98B7224B81C2C04C934; expires=Mon, 24-Aug-2015 16:00:29 GMT; domain=wyu.edu.cn; path=/
)
访问主页就已经有 session 了,你读验证码时不带上是不行的



可以用curl_setopt($ch,CURLOPT_HTTPHEADER,"Set-Cookie: ASPSESSIONIDCQAATSAR=HGOCKONAKIMOPBIOFJFHPGFI; path=/");带上吗

$url = 'http://jwc.wyu.edu.cn/student/';print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Connection: close
[3] => Date: Mon, 24 Aug 2015 11:30:29 GMT
[4] => Content-Length: 617
[5] => Content-Type: text/html
[6] => Set-Cookie: ASPSESSIONIDCQAATSAR=HGOCKONAKIMOPBIOFJFHPGFI; path=/
[7] => Server: IIS
[8] => X-Powered-By: WAF/2.0
[9] => Set-Cookie: safedog-flow-item=6BFDB3BC0A21C98B7224B81C2C04C934; expires=Mon, 24-Aug-2015 16:00:29 GMT; domain=wyu.edu.cn; path=/
)
访问主页就已经有 session 了,你读验证码时不带上是不行的


非常感谢 我模拟登陆成功了

人气教程排行