PHP
  Home arrow PHP arrow Page 4 - Application Framework Components: Logi...
Dev Shed Forums 
Administration  
AJAX  
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 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

Application Framework Components: Login/Logout
By: Chris Neeman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    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:
      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


    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.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    PHP ARTICLES

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





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