The concept of Session in PHP

Source: Internet
Author: User
Tags php script sessions time interval valid

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.