This article mainly introduces how php can simulate login to the Founder's educational administration system to capture information about the course schedule. For more information, see
This article mainly introduces how php can simulate login to the Founder's educational administration system to capture information about the course schedule. For more information, see
Course lattice and super curriculum are two applications that must be familiar to college students. They can use their student ID and the password of the educational administration system to import their course tables, you can view it on your phone anytime, anywhere.
In fact, if we know a little about php, we can also make a web application like this.
1. Fix the verification code
In fact, this is a small bug in the square. When we enter the login interface, the browser will request the server, and the server will generate a verification code image. If we do not request this image, the official background will not generate the corresponding verification code, so we have the opportunity to enjoy it ~ At this time, we can smoothly enter without entering the verification code. You can disable access to the address of the verification code on your computer, and then try to see if this is true ~ Of course, this is only valid for the square.
2. php curl simulated Login
The next step is the relevant code. I believe many people like me only like to look at examples. For a long story, let's turn to the next step ...... But this habit is still not good ...... Not much nonsense!
// Simulate the login function curl_request ($ url, $ post = '', $ cookie ='', $ returnCookie = 0) {$ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url); curl_setopt ($ curl, CURLOPT_USERAGENT, 'mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0) '); curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ curl, CURLOPT_AUTOREFERER, 1); curl_setopt ($ curl, CURLOPT_REFERER, "here must be replaced with the educational administration system login url "); // enter the educational administration system urlif ($ post) {curl_setopt ($ curl, CURLOPT_POST, 1); curl_setopt ($ curl, CURLOPT_POSTFIELDS, http_build_query ($ post ));} if ($ cookie) {curl_setopt ($ curl, CURLOPT_COOKIE, $ cookie);} curl_setopt ($ curl, CURLOPT_HEADER, $ returnCookie); curl_setopt ($ curl, CURLOPT_TIMEOUT, 20 ); curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); $ data = curl_exec ($ curl); if (curl_errno ($ curl) {return curl_error ($ curl );} curl_close ($ curl); if ($ returnCookie) {list ($ header, $ body) = explode ("\ r \ n", $ data, 2 ); preg_match_all ("/Set \-Cookie :( [^;] *);/", $ header, $ matches ); $ info ['cookies'] = substr ($ matches [1] [0], 1); $ info ['content'] = $ body; return $ info ;} else {return $ data ;}}
3. hidden fields on the logon page of the educational administration system
Example
The Code is as follows:
These things also need to be carried during login. By the way, the function is pasted, and the School of the blogger is leaked ...... Royal Farming University (mainly the application of regular expressions)
// Function getView () {$ url = 'HTTP: // jsf-hzau.edu.cn/default2.aspx'; $ result = curl_request ($ url); $ pattern = '//Is '; preg_match_all ($ pattern, $ result, $ matches); $ res [0] = $ matches [1] [0]; return $ res [0];} // return the classroom query Page's hidden value private function getViewJs ($ cookie, $ xh) {$ url = "http://jw.hzau.edu.cn/xxjsjy.aspx? Xh = {$ xh} "; $ result = curl_request ($ url,'', $ cookie); $ pattern = '//Is '; preg_match_all ($ pattern, $ result, $ matches); $ res [0] = $ matches [1] [0]; return $ res [0];}
4. cookie acquisition
Function login ($ xh, $ pwd) {$ url = 'HTTP: // response = $ this-> getView (); $ post ['txtusername'] = $ xh; // enter the student ID $ post ['textbox2 '] = $ pwd; // enter the password $ post ['txtsecretcode'] = ''; $ post ['lblanguage'] = ''; $ post ['hidpdrs'] =''; $ post ['hidsc'] = ''; $ post ['radiobuttonlist1'] = iconv ('utf-8', 'gb2312 ', 'studen '); $ post ['button1'] = iconv ('utf-8', 'gb2312', 'login'); $ result = curl_request ($ url, $ post ,'', 1); return $ result ['cooker'];}
5. Let's try the course Table query function. The format is messy. Let's take a look. I converted the Course table into a two-dimensional join array.
// Return the Course table string private function classresult ($ xh, $ pwd) {date_default_timezone_set ("PRC"); // set the time zone $ classList = ""; // declare the Course table variable $ cookie = $ this-> login ($ xh, $ pwd); $ view = $ this-> getViewJs ($ cookie, $ xh ); // verify that the password is correct // if the password is correct if (! Empty ($ view) {$ url = "http://jw.hzau.edu.cn/xskbcx.aspx? Xh = {$ xh} "; $ result = curl_request ($ url,'', $ cookie); // save cookiespreg_match_all ('/ ([\ W \ W] *?) <\/Table>/', $ result, $ out); $ table = $ out [0] [0]; // obtain the entire course table preg_match_all ('/([\ W \ W] *?) <\/Td>/', $ table, $ out); $ td = $ out [1]; $ length = count ($ td ); // obtain the course list for ($ I = 0; $ I <$ length; $ I ++) {$ td [$ I] = str_replace ("
"," ", $ Td [$ I]); $ reg ="/{(. *)}/"; if (! Preg_match_all ($ reg, $ td [$ I], $ matches) {unset ($ td [$ I]) ;}}$ td = array_values ($ td ); // re-index the course list array $ tdLength = count ($ td); for ($ I = 0; $ I <$ tdLength; $ I ++) {$ td [$ I] = iconv ('gb2312', 'utf-8', $ td [$ I]);} // convert the Course table to an array function converttoTable ($ table) {$ list = array ('sun' => array ('1, 2' => '', '3, 4' => '', '5, 6' =>'', '7, 8' => '', '9, 10' => ''), 'mon' => array ('1, 2' => '', '3, 4' =>'', '5, 6' => '', '7, 8 '=> '', '9, 10' =>''), 'tues' => array ('1, 2' => '', '3, 4' => '', '5, 6' =>'', '7, 8' => '', '9, 10' => ''), 'wed' => array ('1, 2' => '', '3, 4' =>'', '5, 6' => '', '7, 8 '=> '', '9, 10' =>''), 'thur' => array ('1, 2' => '', '3, 4' => '', '5, 6' =>'', '7, 8' => '', '9, 10' => ''), 'fri' => array ('1, 2' => '', '3, 4' =>'', '5, 6' => '', '7, 8 '=> '', '9, 10' =>''), 'sat' => array ('1, 2' => '', '3, 4' => '', '5, 6' =>'', '7, 8' => '', '9, 10' => '')); $ week = array ("sun" => "Sunday", "mon" => "Monday", "tues" => "Tuesday ", "wed" => "Wednesday", "thur" => "ththursday", "fri" => "Friday", "sat" => "Saturday "); $ order = array ('1, 2', '3, 4', '5, 6', '7, 8', '9, 10 '); foreach ($ table as $ key =>$ value) {$ class = $ value; foreach ($ week as $ key =>$ weekDay) {$ pos = strpos ($ class, $ weekDay); // echo $ pos; if ($ pos) {$ weekArrayDay = $ key; // obtain the first-dimensional keyforeach ($ order as $ key => $ orderClass) in the list Array {$ pos = strpos ($ class, $ orderClass); if ($ pos) {$ weekArrayOrder = $ orderClass; // obtain the break for this course;} break ;}$ list [$ weekArrayDay] [$ weekArrayOrder] = $ class ;} return $ list;} // call the function return converttoTable ($ td);} else {return 0 ;}}
6. Try to query the empty classroom function.