The session is written to the database is not the original PHP session is completely replaced by their own, equivalent to the implementation of the session?

Source: Internet
Author: User
Tags php server php session
I saw a lot of them writing the session to the database. If the session is written to the database, is it the equivalent of implementing the session of the database? The original comes out of the void?

Reply content:

I saw a lot of them writing the session to the database. If the session is written to the database, is it the equivalent of implementing the session of the database? The original comes out of the void?

This question I think first of all to clarify what is the session, the individual feel that the session is a realization, and the nature of the cookie is not the same.

Example Login http://segmentfault.com/

    • When the login succeeds, the server generates a similar diM4og.6c3c602eff435b68a0e2aeca90254482.a random string and associates the string with my ID (1030000000093602), which is stored on the server side , so the server knows diM4og.6c3c602eff435b68a0e2aeca90254482.a which user the string belongs to.

      Of course, the storage method is optional, in file form storage, database, Redis, memcached

    • This string is also sent to the client browser as a cookie when the user logs on successfully diM4og.6c3c602eff435b68a0e2aeca90254482.a . In SF, for example, this string is stored in a sfsess cookie named.

    • In this way, each access after login, the server side will be sent from the client's cookie to read the string in the server-side query whether there is a login record of this string, and some words according to the id display user is logged in.

This is the implementation of the session principle, Python,java do the same site, is the truth

The following is the PHP comes with $_SESSION , in our use of this code, in fact, PHP also did the above things, but it is automatic, do not consider the implementation of concrete. PHP server-side storage session string is stored as a file, the client's cookie name is PHPSESSION , the session expires or something is automatically managed by PHP, of course, the cookie name and expiration time can be configured by PHP changes.

This is the advantage of PHP, in fact, the language needs to be implemented separately the session module it is a code to get it done. Of course, this is also its shortcomings, making it difficult for us to understand the specific concept of the session and the implementation principle.

I saw a lot of them writing the session to the database. If the session is written to the database, is it the equivalent of implementing the session of the database? The original comes out of the void?

So there is no self-loss of the problem, but in a more cock way to achieve the session of the verification, and put aside the code of the PHP fool.

Another: SF should use the Redis storage, Typecho with the database storage, landlord can refer to.

Just change the place where the session is stored, the session still exists, just call it from the database.

  • 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.