Basic PHP Tutorial: COOKIEANDSESSION_PHP tutorial

Source: Internet
Author: User
Basic PHP Tutorial: COOKIEANDSESSION. First of all, you must understand the following basic knowledge: 1. when you browse a webpage, HTTP Protocol 2 and HTTP Protocol 3 are stateless. the whole process is that the user sends a request and the server accepts the request, first, you must understand the following basic knowledge:

1. the web browser uses the HTTP protocol.
2. the HTTP protocol is stateless.
3. the whole process is when the user sends a request, the server accepts the request, responds, and disconnects (stateless, this connection record is not recorded)
4. the HTTP protocol consists of the protocol header and message entity.
5. the Session is on the server and the Cookie is on the client.

Process
1. the user sends a url request to the server. (GET/index. php HTTP/1.1)

2. the server accepts the request and searches for the index. php file on the server.

3. search for the session_ID file on the server. generally, create a file under the % TEMP % folder of the server, for example, windows C: \ winnt \ temp \. for example: sess_e12683c5301033a408419cc9df284f7b File (window2000)
And save some SESSION values in the file.

4. return the processing result to the client and place the session_ID or other information in the response protocol header (set-Cookie). the specific information is determined based on the settings and the server is disconnected.

5. the client receives the message. the browser stores the session_ID in the header of the protocol in a file (cookie) on the client.
Generally in windows, C: \ Documents Ents and Settings \ User name \ Local Settings \ Temporary Internet Files.

The cookie file name is generally
Cookie: username @ dommain

The general content of the Cookie file is:
BAIDUID Cookie name
25D4E67AC34F467A29DB9B8C85C4DEC5 Cookie value
Baidu.com/Cookie valid path
1024 security: number of digits of the 1024 and 1536 MODP Group algorithms
3577998080 Cookie effective date
32067270 modification date
1590083488 creation date
29862897 founder

6. when the client sends a second request to the server, the browser places the values in the corresponding cookie file in the request protocol header.

7. the service accepts the protocol header and the cookie value, so that the server can verify with the saved session file.

Description
A. In the above three steps, if the user saves other session values, these values will be saved to the session file as the content.
B. In the above 4 steps, the service can also send more cookie values to the client.
C. in step 5 above, if the user's browser rejects the cookie, the server sometimes uses session_ID as a parameter attached to the url, therefore, we often see parameters such as PHPSESSID = ******** or JSPSESSID = ****** on some URLs. if the browser accepts cookies, more parameters in B will also be placed in the cookie file.
D. in the above 7 steps, the server will find the corresponding session file based on session_ID. Therefore, you can also obtain other previously saved session values based on the file content.
E. There is a time limit on the session files stored on the server.
F. The cookie file stored on the client has an expiration time.

HTTP Protocol 2 and HTTP Protocol 3 are used to browse the web page. the whole process is that the user sends a request, the server accepts the request, and makes a response...

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.