PHP
  Home arrow PHP arrow 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
    ( Page 1 of 4 )

    The first of the Framework components that we are going to be looking at is central authorization. This component contains two classes, the login and logout classes. Not only do these classes log a user in and out, they also record the times and dates that a user logged in and logged out.

    These records will then be viewed by the department heads and the employees themselves if there is any doubt about whether a particular employee was at work that day or under any other circumstances. So let's take a look at the login class code.

    The Login Class

    Below is the code for the login class:

    <?php
    /* connect to db
    Check if user exists
    log successful login
    */

    class authorization{
     
    function authorization($email=null,$dbpath=null,$pass=null){
       
    global $dbtype, $dbusername;
       
    global $dbpass, $dbhost;
       
    global $dbname, $dbtbl,$date_time;

        //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);
       
    }
       
    //set login status
       
    $this ->loginstatus=FALSE;
       
    //set variables received from user
       
    $this->email=$email;
       
    $this->password=$pass;
       
    $this->errmsg="Your login details could not be found. Please
    try again.";
       
    //set date time value
       
    $this->dt=$date_time;
     
    }
     
    function check_user(){
       
    global $userid,$uname,$access,$did,$err,$em;
       
    //connect to the db server with the user provided dbpath
       
    $dbcon = new DBAL($this->dbp);
       
    //see if the user password and email is in the table
       
    $query ="SELECT uid, upass,CONCAT(name,' ',sname) as
    name,access_level,depid FROM ".$this->dbtbl." WHERE email =
    '".$this->email."'";
       
    $query .="AND isActive = '1'";
       
    $result =$dbcon->a_query($query);
       
    //set the authorization status according to
       
    if(!$result){
         
    $this->loginstatus=FALSE;
       
    }else {
         
    $row=$result->fetchrow();
         
    //compare user submitted password with the one from the
    database:
         
    if($this->password == $row->upass){
           
    $this->userid=$row->uid;
           
    $this->uname = $row->name;
           
    $this->access =$row->access_level;
           
    $this->did =$row->depid;
           
    $this->em=$email;
           
    //$this->email=$row->email;
           
    $this->loginstatus=TRUE;
          
    }
         
    else{
           
    $this->err=$dbcon->showerror();
            
    $this->loginstatus=FALSE;
         
    }//password check
        
    }
       
    $dbcon->disconnect();
       
    return $this->loginstatus;
      
    }
     
    function getid(){
       
    return $this->userid;
     
    }
     
    function getname(){
       
    return $this->uname;
     
    }
     
    function getlevel(){
       
    return $this->access;
     
    }
      function geterr(){
       
    return $this->errmsg;
     
    }
     
    function getdepid(){
       
    return $this->did;
     
    }
     
    function getnewid(){
       
    return $this->nid;
     
    }
     
    function getemail(){
       
    return $this->em;
     
    }

    The main aim of the login class is of course to verify that a user has a right to access the intranet. The class checks to see if the user exists in the database. If so, the user is directed to the main intranet page, otherwise an error message is generated and shown on the login page:



     
     
    >>> 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 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek