_php instance of HTTP protocol post request parameter in PHP

Source: Internet
Author: User

This article introduces the HTTP protocol post request parameters in PHP, the details are as follows:

The information in web development is basically all in post and get request and response, because it is intuitive and easy to understand because of its URL, can post request because of its hidden information, in security, but also to the developers to simulate sending trouble. In the next few posts, I will combine my notes and understanding to explain in detail the several ways PHP makes a POST request, if there is a mistake.

HTTP protocol information is an important part of web development, and understanding it can help us understand the BS interaction more profoundly, and also helps us to understand web development from a lower level. HTTP protocol is a simple and flexible communication protocol, and remember, it is a stateless protocol, that is, it is a memory-free protocol, each time the interaction is separate.

We can view HTTP header information using the "Network" panel of the browser's development tool (ie's F12 Firefox firebug, etc.).

Generally HTTP header information is divided into three categories: request information, response information and interactive information (personally considered as one of the request information).

1, Request information:

When you visit a Web site, the client makes the request information, which does not contain data, but simply contacts the server, prompting the server to return the response information.

The format is two parts: the request line and the message header.

A. Request Line: Methods (Request method) path (Request-station address) Http/version (Protocol/version information)

The common request method has get/post/head/option and so on

B. Message header:

Host (MUST): Hosts and port numbers, port number defaults to 80

Accept: Expecting to receive content type (image/gif text/html */*)

Accept-encoding: Compression type expected to receive (gzip Deflat)

Accept-charset: Desired character set to receive (UTF-8)

Accept-language (ZH-CN)

Cookie: User's Cookie information

Connection: Connection Control

User-agent: Client Information

... ...

The following is a typical request header message:

Get index.php http/1.1
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-encoding:gzip, deflate, SDCH
accept-language:zh-cn,zh;q=0.8
Cache-control:max-age=0
Connection:keep-alive
Cookie:sohuhometab=visit:2; iploc=cn1407; suv=1510312046259910
Host:www.sohu.com
If-modified-since:sat, OCT 2015 12:45:22 GMT
Upgrade-insecure-requests:1
user-agent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.99 safari/537.36

2, Response information

Server return Data

Response information is divided into three parts: status line message header response body

A. Status line: Http/version (Protocol/version information) Status Code status text (a textual description of the status code)

There are 5 types of status codes:

1XX: Temporary response required to continue operation by requestor

2XX: The response was successful and the server successfully responded to the request

3XX: Redirect, requires further action by requestor

4XX: Client error, server not responding properly

5XX: Server-side error, server not responding properly

Specific information can be referred to: HTTP status code detailed

B. Message header:

Server: Servers information

Content-encoding: Data compression format

Content-length: Data length

Content-type: Data type

Cache-control: Cache Control

Connection: Connection Control

Date: Dates Information

Expires: Returns expiration information for data

Last-modified: Returns the last modification time

Set-cookie: Set the Cookie information for the client

... ...

C. Response body

That is, the page data that is returned is displayed in the HTML document form.

The following are common response messages

http/1.1 OK

Cache-control:no-cache
Connection:close
Content-encoding:gzip
content-length:6947
content-type:text/html; Charset=gbk
Date:sat, OCT 2015 13:30:11 GMT
Expires:-1
Pragma:no-cache
Proxy-connection:keep-alive
server:nginx/1.2.5
SET-COOKIE:JSESSIONID=YIUUG4YEJHC1CDBZYDOXLCPN; path=/

3, interactive information

Is the request information that contains the request data is common in the user uploads the file registration and so on

It is divided into three parts: Request line message header request body

A. The same request line as the request information

B. Adding data about the request body based on the request header

Content-type: Content Type of uploaded information

Content-length: The length of the uploaded information

... ...

C. Request Body:

That is, the requested specific data string (NAME=XXX&PASSWORK=XXX), which, of course, sometimes encrypts post information for security reasons.

The following is a typical request message:

Get login.php http/1.1
Host:passport.sohu.com
Accept:text/html,application/xhtml+xml,application/xml
Accept-encoding:gzip, deflate
accept-language:zh-cn,zh;q=0.8
Cache-control:max-age=0
Connection:keep-alive
content-length:166
content-type:application/x-www-form-urlencoded
referer:http://mail.sohu.com/
user-agent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.99 safari/537.36
Form Data
domain=sohu.com&callback=passport20008375022711697966_cb1446298206568&appid=1113&userid=fdffdf% 40sohu.com&password=a3f4384c2bc44fa909ffd0ecc5fa8eb9&persistentcookie=0

Understand what the browser sent to the server, it is not difficult to disguise it as a server in other ways.

In the next section, I'll explain how PHP and JS handle the most basic URLs, while the Get Requests section is also ready to simulate sending a POST request.

If you think this blog is helpful to you, you can recommend or point to praise, if you have any questions, you can also leave a message, a discussion, thank you.

Related Article

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.