[PHP learning logs] the use of simple Sessions first provides some explanations of Sessions: Currently, the most practical network protocol is HTTP Hypertext Transfer Protocol, which is & ldquo; stateless & rdquo; the so-called & ldquo; stateless & rdquo; refers to the & ldquo; Status & rdquo; in which the user and the server do not need to be stored for interaction ;. Session is the use of & ldquo; Session Control & rdquo; [PHP learning log] Simple Session in network applications
First, let's explain some Session explanations: Currently, the most practical network protocol is HTTP Hypertext Transfer Protocol, which is "stateless, the so-called "stateless" refers to the "state" in which the user does not store the interaction when interacting with the server ". Session is the "Session control" module in network applications. Therefore, the Session object stores the information required for a specific user Session, that is, the previously mentioned "status" information. In this way, when a user jumps between Web pages of an application, the variables stored in the Session object will not be lost, but will continue to exist throughout the user Session, in this way, the user interacts with the server.
Here I learned how to use PHP sessions, so I first pasted a piece of code:
1
The session is directly enabled here. when this method is called, the server will identify whether a session already in use exists. If yes, the server will directly call this session. If no session exists, the server restarts a session and specifies a unique ID for it. Is the reliability of a session guaranteed? (That is, we need to enable the same session on different PHP pages) the answer is yes. The system will call "session_start () the session with the same ID is used. Then I will post a piece of code:
1
It can be seen that this code differs from the previous code by calling the "session_id ()" method. Here, the "session_id ()" method has two functions:
- Enable session with the specified id
- Obtain the id of the currently enabled session
Here, we obviously enable this session by specifying an id = id enabling method. the advantage is that session calls are more stable. (It is not recommended to do this directly. you can use cookies to store session IDs for stable session calls)