What is session in web?

It is difficult to directly translate Session into Chinese, and it is generally translated into time domain. In computer terminology, Session refers to the time interval during which an end user communicates with the interactive system, usually referring to the time elapsed from logging into the system to logging out of the system.

Specifically, the session in the Web refers to the period of time that elapses from when a user browses a website, from entering the website to closing the browser, that is, the time the user spends browsing the website. Therefore, from the above definition, we can see that Session is actually a specific time concept.

It should be noted that the concept of a Session needs to include a specific client, a specific server, and an uninterrupted operation time. The session in which user A establishes a connection with server C and the Sessions in which user B establishes a connection with server C are two different sessions.

So what is Session's solution? We know that users often need to browse many pages when they visit a website. For a website built by PHP, users need to execute many PHP scripts during the visit. However, due to the characteristics of the HTTP protocol itself, the user needs to re-establish a connection with the Web server every time a PHP script is executed.

And due to the characteristics of stateless memory, this connection cannot get the state of the last connection. In this way, the user assigns a variable in a PHP script, but cannot get the value of the variable in another PHP script. For example, the user sets $user="wind" in the PHP script responsible for login, but cannot get the value "wind" by calling $user in another PHP script. That is, there is no way to set global variables in PHP. The variables defined in each PHP script are local variables that are only valid within that script.

The Session solution is to provide a way to define global variables in PHP scripts, so that the global variables are valid for all PHP scripts in the same Session. As we 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 the global variable defined in a Session refers to all PHP accessed by the user corresponding to this Session.

For example, user A defines a global variable $user="wind" through Session, and user B defines a global variable $user="jane" through Session. Then in the PHP script accessed by user A, the value of $user is wind.

In ASP and ASP.NET
Session is a Web server-based method for maintaining state. Session allows any object to be persisted throughout a user session by storing the object in the web server's memory.
Sessions are typically used to
store information that needs to maintain its state throughout a user session, such as login information or other information the user needs when browsing a web application.
Stores objects that only need to maintain their state across page reloads or across a set of pages grouped by functionality.
The role of the Session is that it maintains the user's state information on the Web server for access from any page at any time. Because the browser does not need to store any of this information, any browser can be used, even a browser device like a PDA or cell phone.
Limitations of this persistence method
As more and more users log in, the amount of server memory required by the Session increases.
Each user accessing the Web application generates a separate Session object. The duration of each Session object is the time of user access plus the time of inactivity.
If many objects are kept in each session, and many users are using the web application at the same time (creating many sessions), the amount of server memory used for session persistence can be large, affecting scalability

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326565540&siteId=291194637