Php implements simulated login to the Founder's educational administration system to capture course schedules

Source: Internet
Author: User

Php implements simulated login to the Founder's educational administration system to capture course schedules

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!

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

// Simulate 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, "you must change it to the educational administration system logon 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 the Code 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)

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

// Hidden fields on the login page

 

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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

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 ['cookies'];

}

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.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

// Return the Course table string

Private function classresult ($ xh, $ pwd ){

Date_default_timezone_set ("PRC"); // set the time zone

$ ClassList = ""; // declare Course table Variables

 

$ 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 list 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 in the list Array

Foreach ($ order as $ key => $ orderClass ){

$ Pos = strpos ($ class, $ orderClass );

If ($ pos ){

$ WeekArrayOrder = $ orderClass; // The number of times the course is obtained

Break;

}

}

Break;

}

}

$ List [$ weekArrayDay] [$ weekArrayOrder] = $ class;

}

Return $ list;

}

 

// Call a function

Return converttoTable ($ td );

} Else {

Return 0;

}

}

6. Try to query the empty classroom function.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

// Empty classroom query results

Public function roomresult (){

$ Xh = ""; // set the student ID

$ Pwd = ""; // password corresponding to the student ID

 

$ Cookie = $ this-> login ($ xh, $ pwd );

$ Url = "http://jw.hzau.edu.cn/xs_main.aspx? Xh = {$ xh }";

$ Result = curl_request ($ url, '', $ cookie); // saved 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 '] = '1970-2014'; // academic year

$ Post ['ddlsyxq'] = '1 ';

$ Post ['jslb'] = '';

$ Post ['xiaoq'] = '';

 

$ Post ['kssj'] = $ _ GET ['start']; // start time of the submitted Query

$ Post ['sjd '] =_ _ GET ['class']; // submitted course times

 

$ Post ['xn '] = '2014-2014'; // academic year

$ Post ['xq'] = '2'; // term

$ Post ['xqj'] = '6'; // The Day of the day of the week

$ Post ['dpdatagrid1: txtPageSize '] = 90; // 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 at the front of the page

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.