What is a session? Session direct translation into Chinese is more difficult, generally translated into time domain. In computer terminology, session refers to the time interval between a terminal user communicating with an interactive system, usually the time elapsed between registering into the system and logging off from the system. The session specific to the Web refers to the time when a user browses to a Web site, from entering the site to closing the browser, which is the time the user spends browsing the site. So from the above definition we can see that the session is actually a specific time concept.
It should be noted that the concept of a session needs to include specific clients, specific server side, and uninterrupted operating time. A the session where a user and C server establish a connection is two different sessions from the sessions when the connection is made to the B user and the C server.
So what is the session solution? We know that when users visit a website, they often need to browse many pages. For a Web site built through PHP, users need to execute a lot of PHP scripts during the visit. However, because of the characteristics of the HTTP protocol itself, users need to re-establish the connection with the Web server for each execution of a PHP script. And because of the state of the memory, this connection can not get the last connection status. This allows the user to assign a variable in a PHP script, but not the value of the variable in another PHP script. For example, the user sets the $user= "Wind" in the PHP script that is responsible for logging in, but cannot get the "wind" value in another PHP script by calling $user. In other words, you cannot set global variables in PHP. The variables defined in each PHP script are local variables that are valid only within this script.
The session solution is to provide a way to define a global variable in a PHP script so that the global variable is valid for all PHP scripts in the same session. As we mentioned above, session is not a simple concept of time, and a session includes specific users and servers. So in more detail, the scope of the global variable defined in a session refers to all PHP that the user of the session accesses.
For example, a user defines a global variable $user= "Wind" through the session, while the B user $user= "Jane" through the global variable defined by the session. So in the PHP script that a user accesses, the value of $user is wind.