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.

  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



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:

/* 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 ->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->errmsg="Your login details could not be found. Please
try again.";
//set date time value
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 =
$query .="AND isActive = '1'";
$result =$dbcon->a_query($query);
//set the authorization status according to
}else {
//compare user submitted password with the one from the
if($this->password == $row->upass){
$this->uname = $row->name;
$this->access =$row->access_level;
$this->did =$row->depid;
}//password check
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


- 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: