HomePHP Page 3 - Storing PHP Sessions in a Database
Overriding the session storage - PHP
There are many reasons to utilize sessions when creating a web-based application using PHP. Session information, by default, is stored in a file on your web server. But what if that becomes a problem? In this article, I'll talk about why you might want to move your PHP sessions to a database, and show you how to do it.
As I just said, the session_set_save_handler() function will allow us to override the default method of storing data. According to the documentation, here is the format for this function:
In the above example, the SessionManager() class and its constructor are created. You will notice that instead of merely passing function names into the session_set_save_handler() function, I sent arrays allowing me to identify class methods as the intercepts for the session actions.