Use PHP to implement simulated login of Zhengfang Academic Affairs System

WBOY
Release: 2016-07-29 08:56:19
Original
2085 people have browsed it

The first time I used PHP to implement simulated login, it really took me a long time. What’s quite fun is that I gained everything slowly by exploring it bit by bit. One thing I still don’t understand is why I can log in without submitting the verification code information. I think it might be a bug!

If you want to simulate login, you must first open the browser to log in to the website you want to simulate login and then press F12 to find the data to be submitted for simulated login. Like Zhengfang, there is a hidden __VIEWSTATE variable that needs to be expressed using regular expressions. Use formula matching to find the value of this variable. After logging in, you will find your personal information on the page and save your cookie in the code so that you can jump to another page you want to query. My code is for querying results. If you are interested in the method, you can communicate with me and discuss it together!

<span style="font-size:14px;"><?php
	$url = "http://jw.jxust.edu.cn"; 
	$username = &#39;&#39;; //设置自己的账号
	$password = &#39;&#39;; // 设置自己的密码
	$ch1 = curl_init();
	curl_setopt($ch1, CURLOPT_URL, $url);
	curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
	$data = curl_exec($ch1);
	curl_close($ch1);
	$pattern = &#39;/<input type="hidden" name="__VIEWSTATE" value="(.*)"/&#39;; //正则表达式匹配__VIEWSTATE
	preg_match_all($pattern, $data, $matches);
	$result = $matches[1][0];
	//print_r($result);
	$post1 = array(                     //必要的提交信息
		&#39;__VIEWSTATE&#39; => $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="(.*)"/&#39;;   
	/*  又要获取__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(     //提交要查找的信息的数据
		&#39;__VIEWSTATE&#39; => $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>
Copy after login

The above introduces the use of PHP to implement simulated login of the Zhengfang Academic Affairs System, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template