PHP
  Home arrow PHP arrow Page 4 - Application Framework Components: Login/Logout
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? 
Google.com  
PHP

Application Framework Components: Login/Logout
By: Chris Neeman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2007-09-04


    Table of Contents:
  • Application Framework Components: Login/Logout
  • Login Class Functions
  • Setting up the SQL Query
  • The Remaining Login Class Functions

  • 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


    Application Framework Components: Login/Logout - The Remaining Login Class Functions
    ( Page 4 of 4 )

    The remaining seven functions simply retrieve individual bits of information based on the outcome of the check_user () function. If you go back to the function, you will notice that we stored some global variables and assigned values from the SQL query. Those values can now be retrieved by the program as and when needed:

    This function retrieves the user id:

    function getid(){
     
    return $this->userid;
    }

    This function retrieves the user name:

    function getname(){
     
    return $this->uname;
    }

    This function retrieves the user access level:

    function getlevel(){
     
    return $this->access;
    }

    Retrieves the error message:

    function geterr(){
     
    return $this->errmsg;
    }

    This function retrieves the department id of the user concerned:

    function getdepid(){
     
    return $this->did;
    }

    This function retrieves the new user id:

    function getnewid(){
     
    return $this->nid;
    }

    This function retrieves the user email address:

    function getemail(){
     
    return $this->em;
    }

    These seven functions will be used to set up the sessions for the user at login. The next function simply logs the time and date that the user logged in.

    First we set some global variables:

    function log_access(){
     
    global $uid,$nid;

    Then we connect to the database server with the database path that I provided:

    //connect to the db server with the user provided dbpath
    $dbcon = new DBAL($this->dbp);

    We then build the SQL query. The query simply inserts the date and time of login for a particular user. To make sure that the log in date and time is inserted for the correct user, the userid variable is used. If this userid does not exists, the query will return an error:

    $query_ins = "INSERT INTO logtbl SET u_id='".$this->userid."',
    start_sess='".$this->dt."',end_sess='0000-00-00 00:00:00',duration='0'";

    The query is then executed, like so:

    $result =$dbcon->a_query($query_ins);

    If the result of the query is false, we store  the error message as shown below:

    if(!$result){
     
    $this->errmsg=$dbcon->showError() . "n";
     
    return FALSE;

    Otherwise, if the result of the query is true, then we collect the new id of the record that we just inserted. This id will then be used when we log out the user:

        }else {
         
    $this->nid=mysql_insert_id();
          
    $dbcon->disconnect();
         
    return TRUE;
        }
      }
    }  //end class
    ?>

    That covers the login class. Below is an outline of the configuration file for the login class. Some of the database variables that we used in the constructor function are stored here:

    <?php
    //db connection creds
    $dbtype = 'mysql';
    $dbhost = 'localhost';
    $dbname = 'intranet';
    $dbtbl = 'users';
    $dbusername = 'root';
    $dbpass = '';
    $dbpath = "$dbtype://$dbusername:$dbpass@$dbhost/$dbname";
    $date_time=date("Y-m-d G:i:s");
    ?>

    Hopefully some of the code in the constructor function will begin to make sense to you. The configuration information above sets up various variables that are used in the login and logout classes.

    Conclusion

    In the follow-up article will look at the logout class before writing a test application to test the login class. We will also discuss the database tables that are going to store the information about intranet users. Both of these tables have very simple structures, but are very effective in their functions. The logout class will also contain a function to record the time and date that the user is going to log out. We will look at this function in great detail.



     
     
    >>> More PHP Articles          >>> More By Chris Neeman
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek