This article mainly introduces about how to store the session in the database, has a certain reference value, now share to everyone, the need for friends can refer to
How to store the session in a database can be combined with a data table design description.
By default php.ini Session.save_handler = files, which is the session is stored as a file.
If you want to change to a database or other storage mode, you need to change the settings so that Session.save_handler = user.
In addition to being configured in php.ini, you can configure it separately in the PHP page, using
Ini_set (' Session.save_handler, ' user ') to set the session storage mode, set to user-defined storage.
After you have set up the storage method, you need to use the Session_set_save_handler () function.
This function is a function that sets the session save procedure at the user level. The function has 6 parameters, these 6 parameters are actually the names of 6 custom functions, which represent the opening, closing, reading, writing, destroying, GC (garbage Collection) of the session respectively.
The sample code is as follows:
function open () {} function Close () {} function read () {} function write () {} function Destroy () {} function GC () {} session_set_save_handler ("Open", "close", "read", "write", "destroy", "GC"); Session_Start ();
Now you can use the session as usual.
The database structure is as follows:
session_id, Session_value, Expire_time, stores the ID and value of the SessionID, respectively, and the expiration time.