The Chinese translation of the session is called "conversation", whose meaning is a series of actions/messages from the beginning to the end, such as calling from the phone to the telephone to hang up the phone in the middle of a series of processes can be called a sessions. At present, the understanding of session in the community is very confusing: sometimes we can see the words "during a browser session, ...", where the conversation is from a browser window open to the closure of this period; You can also see the phrase "user during a session", which may refer to a series of actions by a user, such as the process of logging on to an online purchase from a login to an option to checkout, but sometimes it may just refer to a connection; the difference can only be inferred by context.
However, when the term session is associated with a network protocol, it also tends to imply a "connection-oriented" and/or "hold State" two meanings, "connection-oriented" refers to the communication between the two parties before the communication to establish a communication channel, such as telephone, until the other side of the telephone communication to start. "Staying state" means that one side of the communication can associate a series of messages so that the messages can be interdependent, such as a waiter who can recognize the old customer again and remember that the last time the customer owed the store a dollar. Examples in this category are "one TCP session" or "one POP3 session".
Given that this confusion is immutable, it is difficult to define a uniform standard for the session to be defined. And in reading the session-related material, we can only infer the understanding by context. However, we can understand this: for example, we call, from the moment of dialing to hang up the phone, because the phone is always connected to the state, so the status of this switch is called session. It is the visitor and the entire website interaction process always exists the public variable, when the client does not support the cookie, in order to guarantee the data to be correct, the security, uses the session variable. Visitors to the site are assigned a unique identifier, known as the session ID. It is either stored on the client's cookie or passed through the URL.
So what is the use of the session?
When shopping on the Internet, everyone has used a shopping cart, you can always add the goods you buy to the shopping cart, and finally go to the cashier checkout. Throughout the process, the shopping cart has been playing the role of temporary storage of selected goods, using it to track the activities of users on the site, this is the role of the session, it can be used for user identity authentication, program status records, transfer between the parameters of the page.
In the implementation of the session, cookie technology is used to save a cookie containing the session_id on the client, and to save additional session variables on the server side, such as Session_name and so on. When the user requests the server also sends the SESSION_ID together to the server, through session_id extracts is saved on the server side the variable, can identify the user is who. It is also not difficult to understand why the session sometimes fails.
When the client disables cookies (click "Tools" in IE-"Internet Options", click "Security" in the pop-up dialog box, "Custom Level", "Allow each dialog cookie" to be disabled), SESSION_ID will not be delivered, and the session fails. However, PHP5 can automatically check the cookie status on the Linux/unix platform, and if the client is set to disable, the system automatically attaches the session_id to the URL for delivery. The Windows host does not have this capability.
The session's invention fills the limits of the HTTP protocol.
The HTTP protocol is considered a stateless protocol and the user's browsing status is not known, and the server loses contact with the browser when it completes its response on the service side. This is consistent with the HTTP protocol's original purpose, the client simply needs to download certain files to the server, neither the client nor the server is required to record each other's past behavior, and each request is independent, like a customer's relationship to a vending machine or an ordinary hypermarket.
Therefore, the user's information is recorded through the session, so that the user can confirm the request to the Web server again in this capacity. The invention of the session allows a user to save his information when switching between multiple pages. Website programmers have the experience that the variables on each page can not be used on the next page (although Form,url can also be implemented, but this is a very unsatisfactory way), and session of the registered variables can be used as a global variable.