PHP Remote logon to Zhengfang Educational Administration System Based on curl background, curl Remote Login

Source: Internet
Author: User

PHP Remote logon to Zhengfang Educational Administration System Based on curl background, curl Remote Login

This article describes how to remotely log on to the Zhengfang educational administration system in PHP Based on curl background. We will share this with you for your reference. The details are as follows:

He finally figured out how to solve this problem last year, but the verification code must be filled in.

If you can automatically identify the verification code like 360, it will be okay. No more nonsense. Back to question

CURL is used here.

Design Concept: first log on to the page to obtain COOKIES, and then take the cookies to the server for verification code. Finally, all the information required by the server is provided.

(This kind of thinking completely simulates the browser's access to the page. The fundamental difference is that people are still machines)

Public function index () {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); // you can set curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_file ); // The path of the main cookie. The cookie curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1) on the SAVE page; // The returned result is automatically output $ response = curl_exec ($ ch ); curl_close ($ ch );}

Visit the homepage of the Zhengfang educational administration system. The first is to get the HTML on the page and the second is to get cookies.

Other questions? How to obtain HTML?

If you carefully observe the HTML of the homepage of the educational administration system, you will find many hidden fields, and these fields are changed.
So you can retrieve all the HTML and parse it, and then extract all the required fields.

HTML Structure

If you do not see it, hidden fields are required for data submission and cannot contain many fields.

Page Effect

Next I will discuss the most important question: How can I obtain the verification code?

At first, I want to directly

 

No? Although the verification code is provided, it does not belong to you. Therefore, when you log on remotely, the system will tell you that the verification code is incorrect.

How can I obtain my own verification code? At this time, we naturally think of cookies.

How does the server tell whether the browser request is the same person? Check the sessionid in cookies.

In this way. Take the cookies you obtained on the home page and ask the server for your verification code. Will it give an error?

Public function getImg () {$ url = "http: // xxxx/CheckCode. aspx "; $ filedir = SITE_PATH. "/TMP/Cookies"; $ cookie_file = $ filedir. "/cookie.txt"; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file); // curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_TIMEOUT, "10"); header ("Content-type: image/gif"); // The format varies depending on the image format, please note echo curl_exec ($ ch); curl_close ($ ch );}

Then you can call this method on other pages to obtain the verification code.

The PHP requests of CURL belong to two different threads than the PHP requests sent by the browser. Therefore, their cookies are shared differently.

In this way, you can log on, but do not assume that you have logged on. You can operate on all the functions, and you will be wrong. There is also a small detail ..

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.