the182guy Posted April 30, 2009 Share Posted April 30, 2009 Hi all, I'm trying to create a session class that overrides the default session handlers so I can store them in the database. I have a mysqli object connected to my database in a variable called $GLOBALS['CLASS_DB'] When the _SessionWrite function is called, my global database object seems to dissappear, I get the error 'undifined index CLASS_DB'. Here's the write function: public function _SessionWrite($id, $data) { $id = $GLOBALS['CLASS_DB']->real_escape_string($id); //error here saying undefined index CLASS_DB //more code } The global database object exists and works in the other session functions such as _SessionRead. Any ideas? Link to comment https://forums.phpfreaks.com/topic/156241-problem-with-session-write-function-when-storing-sessions-in-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 30, 2009 Share Posted April 30, 2009 From the session_set_save_handler documentation - Warning As of PHP 5.0.5 the write and close handlers are called after object destruction and therefore cannot use objects or throw exceptions. The object destructors can however use sessions. It is possible to call session_write_close() from the destructor to solve this chicken and egg problem. Link to comment https://forums.phpfreaks.com/topic/156241-problem-with-session-write-function-when-storing-sessions-in-database/#findComment-822624 Share on other sites More sharing options...
the182guy Posted April 30, 2009 Author Share Posted April 30, 2009 Cheers, PFMaBiSmAd. I think I can solve this by keeping a property to store the row ID of the session. If I check that this exists with a valid number then it should solve the problem. Link to comment https://forums.phpfreaks.com/topic/156241-problem-with-session-write-function-when-storing-sessions-in-database/#findComment-822649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.