PHP
  Home arrow PHP arrow Page 3 - Using Session Handling Objects to Maintain the State of Applications with PHP Sessions
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Using Session Handling Objects to Maintain the State of Applications with PHP Sessions
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 25
    2006-05-10


    Table of Contents:
  • Using Session Handling Objects to Maintain the State of Applications with PHP Sessions
  • A procedural implementation of the “session_set_save_handler()” function
  • Developing an object-oriented session management module
  • Coding the session handling class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using Session Handling Objects to Maintain the State of Applications with PHP Sessions - Developing an object-oriented session management module
    ( Page 3 of 4 )

    Actually, creating an object-oriented session handling class is much simpler than you might have thought initially. The nitty-gritty of the whole development process rests on converting the prior callback functions to methods of the session handling class. In accordance with this idea, the basic structure of a session managing class can be defined like this:

    // define 'SessionHandler' class

    class SessionHandler {
        function SessionHandler(){
            // code to register class methods goes here
        }
        function openSession(){
            // no specific implementation is required here
            return true;
        }
        function closeSession(){
            // no specific implementation is required here
            return true;
        }
        function readSession(){
           // code to read session data goes here
        }
        function writeSession(){
            // code to write session data goes here
        }
        function gcSession(){
            // code to delete garbage session data goes here
        }      
    }

    As shown above, the skeleton of the corresponding session handling class is basically made up of the previous six callback functions, which of course have been defined as class methods. At first glance, you can see that encapsulating all the session handling methods behind the structure of a class comes in very useful for constructing a centralized mechanism to manage sessions within a specific PHP application.

    I don't mean that an object-based approach is better that a procedural approach; that would be a misconception. I just want you to realize the convenience of having all the methods integrated into one class, which can be very handy in case you’re developing a Web application purely comprised of PHP objects.

    At this point, you saw how the structure of the session handling class looks. Now, it’s time to leap forward and provide a specific implementation for each of its methods. Keep reading to learn more.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT