Home arrow PHP arrow Application Framework Components: Login/Logout

Application Framework Components: Login/Logout

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.

TABLE OF CONTENTS:
  1. Application Framework Components: Login/Logout
  2. Login Class Functions
  3. Setting up the SQL Query
  4. The Remaining Login Class Functions
By: Chris Neeman
Rating: starstarstarstarstar / 10
September 04, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: