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.