用php实现正方教务系统的模拟登陆

php中文网
发布: 2016-07-29 08:56:19
原创
2467人浏览过

第一次用php实现模拟登陆真的是弄了好久,还挺好玩的就是,都是自己一点一点探索的收获还是慢慢的。到现在还有一点没弄明白的就是为什么不用提交验证码信息也能登陆,感觉可能是bug吧!

想要实现模拟登陆,首先要打开浏览器登录你想要模拟登陆的网站然后按F12去找到模拟登陆要提交的数据,像正方还有个隐藏的__VIEWSTATE的变量需要用正则表达式匹配找到这个变量的值,登陆进去了你就会在页面发现你的个人信息并在代码中注意保存你的cookie以便于跳转到另一个想要查询的页面,我的代码就是查询成绩的方法,有兴趣的可以与我交流一起探讨!

百灵大模型
百灵大模型

蚂蚁集团自研的多模态AI大模型系列

百灵大模型 177
查看详情 百灵大模型
<span style="font-size:14px;"><?php
	$url = "http://jw.jxust.edu.cn"; 
	$username = ''; //设置自己的账号
	$password = ''; // 设置自己的密码
	$ch1 = curl_init();
	curl_setopt($ch1, CURLOPT_URL, $url);
	curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
	$data = curl_exec($ch1);
	curl_close($ch1);
	$pattern = '/<input type="hidden" name="__VIEWSTATE" value="(.*)"/'; //正则表达式匹配__VIEWSTATE
	preg_match_all($pattern, $data, $matches);
	$result = $matches[1][0];
	//print_r($result);
	$post1 = array(                     //必要的提交信息
		'__VIEWSTATE' => $result,
		'txtUserName' => $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 = '/<input type="hidden" name="__VIEWSTATE" value="(.*)"/';   
	/*  又要获取__VIEWSTATE,  注意每个模块的的__VIEWSTATE都不一样  */
	preg_match_all($pattern, $data, $matches);
	$cj__VIEWSTATE = $matches[1][0];


	//模拟登陆获取成绩信息
	$ch4 = curl_init();
	curl_setopt($ch4, CURLOPT_URL, "http://jw.jxust.edu.cn/xscj_gc.aspx?xh=$username&gnmkdm=N121605");
	$post2 = array(     //提交要查找的信息的数据
		'__VIEWSTATE' => $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);
?></span>
登录后复制

以上就介绍了用php实现正方教务系统的模拟登陆,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号