Name | Modified | Size | Downloads / Week |
---|---|---|---|
readme.md | 2012-01-08 | 3.6 kB | |
zebra_session.2.0.2.zip | 2012-01-07 | 11.0 kB | |
zebra_session.2.0.zip | 2011-04-18 | 10.5 kB | |
Zebra_Session 1.0.8 | 2011-01-03 | 9.4 kB | |
Totals: 4 Items | 34.5 kB | 0 |
Zebra_Session, a wrapper for PHP's default session handling functions, using MySQL for storage
Session support in PHP consists of a way to preserve information (variables) on subsequent accesses to a website's pages. Unlike cookies, variables are not stored on the user's computer. Instead, only a session identifier is stored in a cookie on the visitor's computer, which is matched up with the actual session data kept on the server, and made available to us through the $_SESSION super-global. Session data is retrieved as soon as we open a session, usually at the beginning of each page.
By default, session data is stored on the server in flat files, separate for each session. The problem with this scenario is that performance degrades proportionally with the number of session files existing in the session directory (depending on the server's operating system's ability to handle directories with numerous files). Another issue is that session files are usually stored in a location that is world readable posing a security concern on shared hosting.
This is where Zebra_Session comes in handy! Zebra_Session is a PHP class that 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, thus providing both better security and better performance.
The Zebra_Session class is also a solution for applications that are scaled across multiple web servers (using a load balancer or a round-robin DNS) and where the user's session data needs to be available. Storing sessions in a database makes them available to all of the servers!
This class is was inspired by John Herren's code from the Trick out your session handler article and Chris Shiflett's code from his book Essential PHP Security, chapter 8, Shared Hosting, Pg. 78-80.
Zebra_Session's code is heavily commented and generates no warnings/errors/notices when PHP's error reporting level is set to E_ALL.
Starting with version 2.0, Zebra_Session implements row locks, ensuring that data is correctly handled in a scenario with multiple concurrent AJAX requests.
Requirements
PHP 4.4.9+, MySQL 4.1.22+
Installation
Download the latest version, unpack it, and put it in a place accessible to your scripts. After unpacking, you will notice a directory called "install" containing a file named "session_data.sql". This file contains the SQL code that will create a table that is used by the class to store session data. Import or execute the SQL code using your preferred MySQL manager (like phpMyAdmin or the fantastic Adminer) into a database of your choice.
Useful links
How to use | Download latest version | Documentation | Changelog | Comments