Jump to content

Problem with Session Write function when storing sessions in database


the182guy

Recommended Posts

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?

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.