Saving PHP Session Data to a Database
By Tony Marston2005-07-11
Define database table
This is how I have defined the database table which will hold all my session data:
CREATE TABLE `php_session` (
`session_id` varchar(32) NOT NULL default '',
`user_id` varchar(16) default NULL,
`date_created` datetime NOT NULL default '0000-00-00 00:00:00',
`last_updated` datetime NOT NULL default '0000-00-00 00:00:00',
`session_data` longtext,
PRIMARY KEY (`session_id`),
KEY `last_updated` (`last_updated`)
) ENGINE=MyISAM
Please note the following:
| session_id | This is the identity of the session, so it must be the primary key. |
| session_data | This must be big enough to hold the largest $_SESSION array that your application is liable to produce. |
| date_created | This is used to identify when the session was started. |
| last_updated | This is used to identify when the last request was processed for the session. This is also used in garbage collection to remove those sessions which have been inactive for a period of time. |
| user_id | This is used to identify the person to whom this session belongs. The value is provided by the application logon screen. |
Tutorial Pages:
» Introduction
» Define database table
» Define database class
» Define session handler
» Conclusion
