The php Function Session_Set_Save_Handler
The php function session_set_save_handler allows you to set a custom save handler. This allows you to store your session data outside the standard $_SESSION array and avoid storing the same information multiple times in different locations on the server (such as in memory or in databases).
The handler should be a class that implements the SessionHandlerInterface. You can use the __autoload() method to automatically register your handler when a new object of your class is created. This is useful when your class needs to be registered as a session handler (or any other kind of handling).
If you need to read a value from a variable in the $_SESSION array, you can use the getvalue() method of your class. This will return a string that is serialized by the internal engine of php. You should not try to serialize objects in PHP directly by calling the serialize() method, this may result in problems if you have other functions in your class that are called on it such as destructors or constructors.
If you want to write values to a database, make sure that you call addslashes() on the serialized data sent to your custom handler. Without adding slashes, MySQL will not be able to understand the values and will truncate them when they are saved. This is especially important if you are using the MEMORY storage engine with PHP and magic_quotes enabled.