Home > Article > Backend Development > [PHP Learning Log] Simple Session use, php learning log session_PHP tutorial
First, give some explanations of Session: The most practical network protocol at present is HTTP Hypertext Transfer Protocol , it is "stateless". The so-called "stateless" means that it does not store the "state" that needs to be interacted with when the user interacts with the server. Session is the "session control" module in network applications. The Session object therefore stores the information required for a specific user session, the "state" information mentioned earlier. In this way, when the user jumps between the Web pages of the application, the variables stored in the Session object will not be lost, but will persist throughout the user session, thereby achieving the purpose of user interaction with the server.
Here I am learning how to use PHP Session, so I will post a piece of code first:
1 1dbca74775031a7716fb591183fb9ca6
Open the session directly here. When calling this method, the server will identify whether there is already a session that is already in use. If it exists, it will call the session directly; if it does not exist, the server will reopen a session and specify a session for it. Unique ID. And is the reliability of a session guaranteed? (That is, in different PHP pages, we need to open the same session) The answer is yes, the system will use the same ID session every time the "session_start()" method is called in the same session. Then I will post another piece of code:
<span>1</span> <?<span>php </span><span>2</span> <span>session_id</span><span>(id); </span><span>3</span> <span>session_start</span><span>(); </span><span>4</span> <span>//</span><span>......code</span> <span>5</span> ?>
As you can see, the difference between this code and the previous paragraph is the addition of the call to the "session_id()" method. Here is an explanation: The "session_id()" method has two functions:
So here we obviously open this session by specifying an opening method of id=id. The advantage of this is that the session call is more stable. (It is not recommended to do this directly. You can use cookies to store the session ID to achieve the purpose of stable reply)