The native functionality of the PHP session works fine, but ultimately it's a singleton. There are times when you need to maintain state for several applications and within the framework of an already started session (for example, within the application). Technically, you can stop / restart a session after changing session_name()
, but this is impractical / impossible / unsafe in most applications. Using a shared session.save_path
also not an option if one application stores session data with an adapter without a disk.
There is no reason why functionality in native sessions cannot be performed in user code, so has anyone done this?
Update 1: CI_Session is indeed a custom implementation with some useful code, but it is very closely related to CodeIgniter.
Update 2: Here's an API that would be great:
// setup $saveHandler = new UserlandSession_SaveHandler_Files('5;/tmp'); $sess = new UserlandSession($saveHandler); $sess->name('PHPSESSID2'); $sess->gc_maxlifetime = 86400; $sess->setProxy($state); // passed by ref // usage $sess->start(); // stored string unserialized to $state $state['foo'] = 'bar'; $sess->write_close(); // $state serialized to storage
Update 3: I wrote an implementation for PHP5.3.
Steve clay
source share