Best library for PHP Sessions [closed] Best library for PHP Sessions [closed] codeigniter codeigniter

Best library for PHP Sessions [closed]


Did you have a look at Zend_Session?

  • you can pass the session identifier via URL using PHP settings
  • you can expire certain session variables by time or by hops (requests)
  • migration into other apps won't be that easy and I think it's not very good when you mess with $_SESSION when you use Zend_Session
  • Zend_Session has an adpater based-approach for saving session data. A save-handler for DBs is included, but its architecture allows for custom handlers to be passed in.
  • Zend_Session supports validators to check the validity of a session. Here too we have an open architecture that allows you to pass in custom objects for validation.
  • you can lock a session, aka make it read-only
  • you can prevent the instantiation of multiple instances of the same session namespace
  • plus there is a lot more to discover with Zend_Session such as regenerating session ids, issue remember-me-cookies, revoke remember-me-cookies and so on.


Ok, After digging through the custom, non-$_SESSION-based codeigniter lib, the two Kohana and Zend libs (which use $_SESSION), and several other session libraries from other projects I believe that I build the answer to my problem. Something that satisfies all of the things I listed above (except flash data).

Here is the code if anyone wants to use it or read it while building their own library. I left a lot of comments thoroughly explaining the whole thing and would love to have some feedback on it. It supports tokens, flash based uploaders, cookies, session regeneration every 5 mins (or whatever you set) with removal of old sessions, and support for storing sessions in any database, the file system, memchache, or any other form that you want to set.


Have a look Zebra_Session, a wrapper for PHP’s default session handling functions, using MySQL for storage

  • acts as a wrapper for PHP’s default session handling functions, but instead of storing session data in flat files it stores them in a MySQL database, providing better security and better performance

  • it is a drop-in and seemingless replacement for PHP’s default session handler: PHP sessions will be used in the same way as prior to using the library; you don’t need to change any existing code!

  • implements row locks, ensuring that data is correctly handled in scenarios with multiple concurrent AJAX requests

  • one file only

  • mature, highly optimized and constantly developed

  • very good documentation