How the session.invalidate session works

Source: Internet
Author: User
Tags session id
Let's take a look at how the session works. I wonder if you know the identity authentication through the cookie. First, a unique cookie is generated as a token of the user's identity and registered in the database. The user's identity is then determined by comparing the cookie passed by the user with the cookie registered in the database.
This is how the session works.
First, PHP creates a unique string for the user who created the session to mark the user's session. This string is generally referred to as the session Id. Then "Sess" +session ID is a file name (for example, a Session ID of 111, then the file name is sess_111) in the server's file system to establish a file, in the file to save the user in the Session of the global variables defined by the variable name and value. The session ID is then stored in the client's file system as a cookie named Phpsession.
Then, when the user connects to the server again to access a PHP script, PHP obtains the session Id of the user's session from the user's peesession cookie, and according to the session ID The file that holds session information from the server's file system. Finally, the value of the global variable set by the user at the last connection is read from this file.
Therefore, we can see that the session works the same way as the identity authentication described in the previous section. The only difference is that the session saves the information in the server's file system, and we keep the information in the database. Of course, the advantage of using the session is that the data is saved and obtained automatically by PHP, and the direct use of cookies, you need to do their own data storage and acquisition.
The session uses the identity Flag feature of cookies to store information that users need to save while browsing the site on the server. In this way, the session overcomes the shortcomings of the HTTP protocol, prevents the leakage of information, and facilitates the use of programmers, which is a very good solution. However, the function of the session only PHP4 support, PHP3 is not support session. So readers using PHP3 for website building can only use cookies in a direct manner.

The above describes the work of Session.invalidate session, including the session.invalidate aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.