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

Lidisam 2015-08-24 06:54:09
<?php
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{
?>
<form id="form1" name="form1" method="post" action="">
<img src="?img=true" /><!--由服务器端取图片内容并输出-->
<input type="text" name="d" />
<input type="submit" name="button" id="button" value="提交" />
</form>
<?php
}
?>
...全文
271 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
九烟 2016-01-11
  • 打赏
  • 举报
回复
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(); } 这里面加上: curl_setopt($ch,CURLOPT_COOKIEFILE, $cookieFile); //同时发送Cookie 可以,不再提示:注册码有误 不过我遇到了新的问题,” 系统异常,请稍后再试 “ 请问这个怎么解决?
慌乱流蔻 2016-01-05
  • 打赏
  • 举报
回复
楼主能不能教下我,我也卡在模拟登陆这儿了,楼主方便教下我吗
Lidisam 2015-08-26
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
$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 了,你读验证码时不带上是不行的
非常感谢 我模拟登陆成功了
Lidisam 2015-08-24
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
$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=/");带上吗
Lidisam 2015-08-24
  • 打赏
  • 举报
回复
怎么带上session,在哪里带上
引用 1 楼 xuzuning 的回复:
$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弄了很久了 如果可以能告诉下吗
xuzuning 2015-08-24
  • 打赏
  • 举报
回复
$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 了,你读验证码时不带上是不行的

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧