Simulated logon-phpCURL simulates login to the Zhengfang Educational Administration System

Source: Internet
Author: User
The Code is as follows {code...}, but at last it is returned to the logon interface.

$ Cookie_file = tempnam ('. /temp ', 'cookier'); $ login_url = 'HTTP: // 211.64.47.129/default_ysdx.aspx '; $ post_fields = '_ VIEWSTATE = require = & TextBox1 = student ID & TextBox2 = password'; $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_HEADER, 0 ); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setop T ($ ch, CURLOPT_COOKIEJAR, $ cookie_file); curl_exec ($ ch); curl_close ($ ch); $ url = 'HTTP: // 211.64.47.129/xs_main.aspx? Xh = student ID '; $ ch = curl_init ($ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); $ contents = curl_exec ($ ch); preg_match ("/
  • (.*)<\/li>/",$contents,$arr);echo $arr[1];curl_close($ch);
  • But at last, I went back to the login interface.

    Reply content:

    The Code is as follows:

    $ Cookie_file = tempnam ('. /temp ', 'cookier'); $ login_url = 'HTTP: // 211.64.47.129/default_ysdx.aspx '; $ post_fields = '_ VIEWSTATE = require = & TextBox1 = student ID & TextBox2 = password'; $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_HEADER, 0 ); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setop T ($ ch, CURLOPT_COOKIEJAR, $ cookie_file); curl_exec ($ ch); curl_close ($ ch); $ url = 'HTTP: // 211.64.47.129/xs_main.aspx? Xh = student ID '; $ ch = curl_init ($ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); $ contents = curl_exec ($ ch); preg_match ("/
  • (.*)<\/li>/",$contents,$arr);echo $arr[1];curl_close($ch);
  • But at last, I went back to the login interface.

    According to the requirements of the landlord, I wroteHttpClientClass, the code written is as follows, but because there is no test account, the account and password used for testing aretestThe returned result is a logon failure. You only need to modify the account and password in the code.
    HTTPIn the request processCookieByHttpClient/CURLAutomatic processing.

    The Code sent by the landlord should be okay, and I feel that it is not submitted.RadioButtonList1AndButton1The two data.
    And that__VIEWSTATEAlthough it seems to be fixed, it should be obtained from the page for the insurance period, and then submitted for login.

    Code:

    
      Ch = curl_init (); curl_setopt ($ this-> ch, CURLOPT_USERAGENT, 'mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; QQDownload 685; SLCC2 ;. net clr 2.0.50727 ;. net clr 3.5.30729 ;. net clr 3.0.30729 ;. NET4.0C ;. NET4.0E) '); // UA curl_setopt ($ this-> ch, CURLOPT_TIMEOUT, 40); curl_setopt ($ this-> ch, CURLOPT_FOLLOWLOCATION, TRUE ); curl_setopt ($ this-> ch, CURLOPT_AUTOREFERER, true); curl_setopt ($ thi S-> ch, extract, TRUE); curl_setopt ($ this-> ch, CURLOPT_COOKIEJAR, $ cookie_jar); curl_setopt ($ this-> ch, CURLOPT_COOKIEFILE, $ cookie_jar );} function _ destruct () {curl_close ($ this-> ch);} final public function setReferer ($ ref = '') {if ($ ref! = '') {Curl_setopt ($ this-> ch, CURLOPT_REFERER, $ ref) ;}} final public function Get ($ url, $ header = false, $ nobody = false) {curl_setopt ($ this-> ch, CURLOPT_POST, false); curl_setopt ($ this-> ch, CURLOPT_URL, $ url); curl_setopt ($ this-> ch, CURLOPT_HEADER, $ header); curl_setopt ($ this-> ch, CURLOPT_NOBODY, $ nobody); return curl_exec ($ this-> ch);} final public function Post ($ url, $ data = array (), $ header = false, $ nobody = false) {curl_setopt ($ this-> ch, CURLOPT_URL, $ url); curl_setopt ($ this-> ch, CURLOPT_HEADER, $ header); curl_setopt ($ this-> ch, CURLOPT_NOBODY, $ nobody); curl_setopt ($ this-> ch, CURLOPT_POST, true ); curl_setopt ($ this-> ch, CURLOPT_POSTFIELDS, http_build_query ($ data); return curl_exec ($ this-> ch);} const Login_URL =' http://211.64.47.129/default_ysdx.aspx '; $ Http = new HttpClient (tempnam ('. /temp ', 'cookies'); $ html = $ http-> Get (Login_URL); // first request the login page, get _ VIEWSTATEpreg_match ('/name = "_ VIEWSTATE" value = "(. + ?) "/', $ Html, $ vs); if (count ($ )! = 2) {echo 'failed to get viewstate '; exit ();} // construct the data $ data = array ('_ viewstate' = >$ vs [1], // _ VIEWSTATE 'textbox1' => 'username ', // modify the user 'textbox2 '=> 'Password', // and the password 'radiobuttonlist1' => 'studen ', // and the identity type 'button1' => 'login'); $ html = $ http-> Post (Login_URL, $ data ); preg_match ('/language = \ 'javascript \'> alert \(\'(. + ?) \ '\);/', $ Html, $ err); // check whether an error occurs. if an error occurs, the system displays the error message and exits if (count ($ err) === 2) {echo $ err [1]; exit () ;}$ sn = '000000'; // student ID $ html = $ http-> Get (' http://211.64.47.129/xs_main.aspx?xh= '. $ Sn); preg_match ('/
  • \s*(.*)<\/li>/', $html, $result);var_dump($result);
  • Https://github.com/lndj/Lcrawl/tree/dev

    An elegant official academic system crawler.

    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.