The concept of Session in PHP. What is Session? It is difficult to directly translate sessions into Chinese. generally, sessions are translated into the time domain. In computer terminology, Session refers to what is a Session when an end user communicates with an interactive system? It is difficult to directly translate sessions into Chinese. generally, sessions are translated into the time domain. In computer terminology, Session refers to the time interval between an end user and an interactive system for communication. it usually refers to the time between registration and entry into the system and cancellation and exit of the system. Specifically, the Session in the Web refers to the time that the user spends browsing a website from entering the website to closing the browser. Therefore, we can see from the above definition that Session is actually a specific concept of time.
It should be noted that the concept of a Session should include the specific client, specific server, and non-interrupted operation time. The Session in which user A establishes A connection with server C is different from the Session in which user B establishes A connection with server C.
So what is the Session solution? We know that users often need to browse many webpages when accessing a website. For a website built using PHP, users need to execute many PHP scripts during access. However, due to the characteristics of the HTTP protocol, each PHP script executed by a user needs to be re-connected to the Web server. Due to the stateless memory, the connection cannot get the status of the last connection. In this way, the user assigns a value to a variable in a PHP script, but the value of this variable cannot be obtained in another PHP script. For example, if you set $ user = "wind" in the PHP script for logon, you cannot obtain the "wind" value by calling $ user in another PHP script. In other words, global variables cannot be set in PHP. The variables defined in each PHP script are only valid local variables in this script.
The Session solution is to provide a method to define the global variable in the PHP script so that the global variable is valid for all PHP scripts in the same Session. As mentioned above, Session is not a simple concept of time. a Session also includes specific users and servers. Therefore, in more detail, the scope of global variables defined in a Session refers to all PHP files accessed by users corresponding to this Session.
For example, user A defines A global variable $ user = "wind" through Session, while user B defines the global variable $ user = "jane" through Session ". In the PHP script accessed by user A, the value of $ user is wind.
Why? It is difficult to directly translate sessions into Chinese. generally, sessions are translated into the time domain. In computer terminology, Session refers to the communication between an end user and an interactive system...