Php implements simulated login to the 正 system to capture the Course table and the 正 Course table

Source: Internet
Author: User

Php implements simulated login to the 正 system to capture the Course table and the 正 Course table

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 url if ($ 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

Copy codeThe Code is as follows:
<Input type = "hidden" name = "_ VIEWSTATE" value = "dDwyODE2NTM0OTg7Oz61eIbnKVojBioGYtg2vsy2SklwiA =">

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 = '/<input type = "hidden" name = "_ VIEWSTATE" value = "(. *?) "\/>/Is '; preg_match_all ($ pattern, $ result, $ matches); $ res [0] = $ matches [1] [0]; return $ res [0];} // return the hidden value of the classroom query page private function getViewJs ($ cookie, $ xh) {$ url = "http://jw.hzau.edu.cn/xxjsjy.aspx? Xh = {$ xh} "; $ result = curl_request ($ url,'', $ cookie ); $ pattern = '/<input type = "hidden" name = "_ VIEWSTATE" value = "(. *?) "\/>/Is '; preg_match_all ($ pattern, $ result, $ matches); $ res [0] = $ matches [1] [0]; return $ res [0];}

4. cookie acquisition

Function login ($ xh, $ pwd) {$ url = 'HTTP: // jsf-hzau.edu.cn/default2.aspx'; $ post ['_ viewstate'] = $ this-> getView (); $ post ['txtusername'] = $ xh; // enter the student ID $ post ['textbox2 '] = $ pwd; // enter the password $ post ['txtsecretcode'] = ''; $ post ['lblanguage'] =''; $ post ['hiddrs'] = ''; $ post ['SC SC'] = ''; $ 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 ); // saved cookies preg_match_all ('/<table id = "Table1" [\ w \ W] *?> ([\ W \ W] *?) <\/Table>/', $ result, $ out); $ table = $ out [0] [0]; // obtain the entire course table preg_match_all ('/<td [\ w \ W] *?> ([\ 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 ("<br> ", "", $ 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 key foreach ($ 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.

// Empty classroom query result public function roomresult () {$ xh = ""; // set student ID $ pwd = ""; // password for student ID $ cookie = $ this-> login ($ xh, $ pwd); $ url = "http://jw.hzau.edu.cn/xs_main.aspx? Xh = {$ xh} "; $ result = curl_request ($ url,'', $ cookie); // save cookies $ url = "http://jw.hzau.edu.cn/xxjsjy.aspx? Xh = {$ xh} "; $ post ['button2'] = iconv ('utf-8', 'gb2312', 'EMPTY classroom query '); $ post ['_ EVENTARGUMENT'] = ''; $ post ['_ EVENTTARGET'] = ''; $ post ['_ viewstate'] = $ this-> getViewJs ($ cookie, $ xh); $ post ['ddldsz'] = iconv ('utf-8 ', 'gb2312', 'singles'); $ post ['ddlsyxn '] = '2014-2014'; // school year $ post ['ddlsyxq'] = '1 '; $ post ['jslb'] = ''; $ post ['xiaoq'] =''; $ post ['kssj'] = $ _ GET ['start']; // start query time of submission $ post ['sjd '] = $ _ GET ['class']; // submitted Course section $ post ['xn '] = '1970-2014'; // The school year $ post ['xq'] = '2 '; // The term $ post ['xqj'] = '6'; // The Day of the day $ post ['dpdatagrid1: txtpagesize'] = 90; // The number of entries displayed per page $ result = curl_request ($ url, $ post, $ cookie, 0 ); preg_match_all ('/<span [^>] +> [^>] + span>/', $ result, $ out); $ tip = iconv ('gb2312 ', 'utf-8', $ out [0] [3]); // get the prompt content preg_match_all ('/<table [\ w \ W] *?> ([\ W \ W] *?) <\/Table>/', $ result, $ out); $ table = iconv ('gb2312', 'utf-8', $ out [0] [0]); // obtain the query list $ this-> load-> view ("classroom", array ('tip '=> $ tip, 'table' => $ table ));}

In summary, the educational administration systems of every school are different. At this time, we can use firebug in Firefox to capture packets and see what we have submitted.

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.