PHP
  Home arrow PHP arrow Building a Logout Class
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
OLM
 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

Building a Logout Class
By: Chris Neeman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2007-09-05

    Table of Contents:
  • Building a Logout Class
  • Recording the Logout Session
  • The Database Tables
  • Testing the Classes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    Building a Logout Class
    (Page 1 of 4 )

    The main function of the logout class is to log out a user and then redirect the user to the login page. On a programmatic level, the logout class terminates and destroys the session variables that the login class created for the user and also logs the exit time to the database. This article will show you how to create a logout class. It is part of a series on application framework components.

    The class starts off with a constructor function that initializes some of the variables that will be used throughout the class. All of the classes that we will create throughout the next couple of articles will have a constructor function such as the ones we've seen so far. This is because this function basically sets up the database connection for the classes involved. The logout class has two functions, one of which is the constructor function and the other is the log_exit() function, that logs user exit time and date to the database:

    <?php

    class logout{

    The constructor function has two sections. One deals with the database setup and the other simply sets up some variables for use in the class. All the global variables declared here are stored in the configuration file of the login class.  This excludes the $newid and $date_time values that are also shown. The class takes three parameters: the current date and time, the userid and the newid. Both the userid and newid will be stored during user login. Because the logout class simply updates an existing record, it requires these three parameters to accurately set the new values for the right user:

    function logout($cdate,$uid,$nwid){
     
    global $dbtype, $dbusername;
      global $dbpass, $dbhost,$newid;
      global $dbname, $dbtbl,$date_time;

    We then link the database connection credentials and set up a database path or URL. This URL will then be used in subsequent connections to the database:

    //set database connection details:
    $this->dbtbl=$dbtbl;
    $this ->dbp=$dbpath;
    if($dbpath == null){
     
    $this ->dbp=sprintf("%s://%s:%s@%s/%s", $dbtype, $dbusername, $dbpass, $dbhost,$dbname);
    }

    We then initialize some of the internal variables with the globally declared ones.  The newid variable, if you recall, was generated during login and is retrieved by the getnewid() function declared in the authorization class:

      //set logout status
      $this ->logoutstatus=FALSE;
      //set variables received from user
      $this->cdate=$date_time;
      $this->userid=$uid;
      $this->errmsg="";
      $this->newid=$nwid;
    }

    That's it for the login class. The next function will do the actual recording of the users' logout session.

    More PHP Articles
    More By Chris Neeman


     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway