第一次用php实现模拟登陆真的是弄了好久,还挺好玩的就是,都是自己一点一点探索的收获还是慢慢的。到现在还有一点没弄明白的就是为什么不用提交验证码信息也能登陆,感觉可能是bug吧!
想要实现模拟登陆,首先要打开浏览器登录你想要模拟登陆的网站然后按f12去找到模拟登陆要提交的数据,像正方还有个隐藏的__viewstate的变量需要用正则表达式匹配找到这个变量的值,登陆进去了你就会在页面发现你的个人信息并在代码中注意保存你的cookie以便于跳转到另一个想要查询的页面,我的代码就是查询成绩的方法,有兴趣的可以与我交流一起探讨!
$username, 'textbox2' => $password, 'radiobuttonlist1' => iconv('utf-8', 'gb2312', '学生'), 'button1' => '' ); $filecookie = dirname(__file__)./cookie; $ch2 = curl_init(); curl_setopt($ch2, curlopt_url, $url); curl_setopt($ch2, curlopt_returntransfer, 1); curl_setopt($ch2, curlopt_followlocation, 1); curl_setopt($ch2, curlopt_post, 1); curl_setopt($ch2, curlopt_postfields, http_build_query($post1)); curl_setopt($ch2, curlopt_cookiejar, $filecookie); //保存登陆的cookie信息到filecookie文件中 curl_exec($ch2); curl_close($ch2); //模拟登录成绩页面获取__viewstate $ch3 = curl_init(); curl_setopt($ch3, curlopt_url, http://jw.jxust.edu.cn/xscj_gc.aspx?xh=$username&gnmkdm=n121605); curl_setopt($ch3, curlopt_returntransfer, 1); curl_setopt($ch3, curlopt_cookiefile, $filecookie); curl_setopt($ch3, curlopt_referer, http://jw.jxust.edu.cn); $data = curl_exec($ch3); curl_close($ch3); $pattern = '/ $cj__viewstate, 'ddlxn' => '', 'ddlxq' => '', 'button1' => iconv('utf-8', 'gb2312', '按学期查询') ); curl_setopt($ch4, curlopt_returntransfer, 0); curl_setopt($ch4, curlopt_followlocation, 1); curl_setopt($ch4, curlopt_cookiefile, $filecookie); curl_setopt($ch4, curlopt_post, 1); curl_setopt($ch4, curlopt_postfields, $post2); curl_setopt($ch4, curlopt_referer, http://jw.jxust.edu.cn); $data = curl_exec($ch4); //preg_match_all($pattern, $data, $matches); curl_close($ch4);?>
以上就介绍了用php实现正方教务系统的模拟登陆,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。