PHP
  Home arrow PHP arrow Application Framework Components: Logi...
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 
eWeek
 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

    Virtual Tradeshows by Ziff Davis Enterprise - A Unique Opportunity to Connect with IT Experts, Access Information, and Gain Insight on today's Technology

    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

    - 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
    - Working with Multiple Document Nodes with th...




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