PHP Classes

DcSessionManager : Manage sessions using a MySQL table to store data

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Info   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2004-05-11 (11 years ago) RSS 2.0 feedNot enough user ratingsTotal: 1,120 All time: 3,160 This week: 1,235Up
Version License Categories  
dcsessionmanager 1.0GNU General Publi...User Management
Description Author  

This class is meant to manage sessions storing the information about their state in a MySQL database table.

It generates an hash with 64 characters that is used to identify each session and may be passed between pages using cookies or request variables.

This class has security in mind, providing means to prevents session hijack by using 2 hashes (double crypted) in only one "session".

You can store more than 5kbytes of data in each session.

The class provides other features, like:

- Explicitly creating and destroing session
- Register and deleting a session value
- Check if a session key value is assigned

Picture of Guilherme Blanco
Name: Guilherme Blanco <contact>
Classes: 5 packages by
Country: Brazil Brazil
Age: 31
All time rank: 21014 in Brazil Brazil
Week rank: 1587 Down116 in Brazil Brazil Down
Innovation award
Innovation award
Nominee: 2x

Details provided by the author  
 * Class:


 0 - Introduction

 This files means to describe the usage of the refering class.
 This will also include the basic usage, advanced usage and some test cases.

 It's important to remember that any feedback is apreciate. The author will love
to know that his functions is being used in project X, tips, hints, suggestions,
improvement ideas. The project can be improved under requests, suggestions, and
bug discoveries.

 This is a public package, that you can use and modify without any limitations,
as long as the credits to the author were intact. This will provide him more
enthusiam to create another ones, better and this.

 1 - Installing
 Execute the setup.sql in your MySQL server.

 2 - Class Description

 The class is very simple to be used, but the programmer must have to
provide it the basic arguments to restore a session, save it, and get it, allowing
it to works properly.

   2.1 - Constructor

   The basic usage of construtor is:

   $sess = new dcSessionManager();

   This will generate a new Session, depending of the given values.
   NOTE: A Session can be restored via COOKIE, GET or POST Method. If none of them
were defined, a new Session will be created.

     2.1.1 - Possible arguments:

     $expire (first argument) => Define the number of seconds to expire a session.
     Default value is 600 (10 minutes). The argument can be a number (I mean, numeric),
without any quotes, or the "default" string (with quotes). If not defined, the class
will assume as 600 seconds.

     $linkId (second argument) => The connection id (resource link id) to the MySQL table.
     Default if the last connection. You can send this parameter or try to use wihout it.
The class will try to use it, by taking the last connection opened.

   2.2 - Other methods

     hash $return = $sess->getHash();
     Return the hash to be send though the links.

     hash $return = $sess->regenerateHash();
     Return a new hash to be inserted in the sessHandler table. This doesn't reinsert in
the database as a security issue. The programmer must do it manually.

     boolean $return = $sess->setSaveSession( boolean $value );
     If the $value is true, the class try to store a 64 chars encrypted in the user machine,
assigning the behavior of a cookie. If the value is false, use the behavior will be a session,
and will be excluded automatically (by another acess) in the expired time. This function
returns a boolean value. If the execution succed sucessfully, it'll return TRUE, else, FALSE.

     boolean $result = $sess->setSessionValue( string $value [, ...] );
     This method register (and also update) Session values in the current Session. All the 
values here must be in a string format, but refers to an existent array, string, etc. The number 
of parameters are unlimited. Will return TRUE if the execution succed without any problems
and FALSE if not.

     boolean $result = $sess->deleteSessionValue( string $value [, ...] );
     Delete existent Session values. All the values here must be in a string format. The number
of parameters are unlimited. Will return TRUE if the execution succed without any problems
and FALSE if not.

     array $result = $sess->getSessionValues();
     Return all registered values in an associative array.
     mixed $result = $sess->getSessionValueByName( string $name );
     Return a values registered with the key $name.
     boolean $result = $sess->destroySession();
     Destroy an existent session (also unset the cookie).
     boolean $result = $sess->isRegistered( string $name );
     Returns a boolean value (TRUE/FALSE) if the system can find a key registered in the registered
Session values. This function follow the same behavior as session_is_registered($name) in PHP.

  There're some other methods defined in the class, but they're internal, and should not be used by
the programmer.

 3 - Usage
 Check out example(s) in the ZIP File.
  Files folder image Files  
File Role Description
Plain text file Class Class of the environment
Accessible without login Plain text file README.txt Doc. Class documentation
Accessible without login Plain text file setup.sql Data MySQL Table
Accessible without login Plain text file test_case1.php Example First example of usage

 Version Control Unique User Downloads Download Rankings  
 0%Total:1,120All time:3,160
 This week:0This week:1,235Up