Home arrow PHP arrow Page 2 - Application Framework Components: Login/Logout

Login Class Functions - PHP

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



The class has nine functions. Let's take a closer look, starting with the first one.

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

The first function is what we call a constructor function. Its main aim is to initialize some of the variables that are going to be used throughout the class. This function has the same name as the class itself and takes three parameters: the email address, database path and pass (shortened for password). So whenever the class is used, it will need these three parameters to be passed. Two of these parameters, as you've probably worked out by now, are supplied by the user during login. You will also notice some global variables that I've declared:

global $dbtype, $dbusername;
global $dbpass, $dbhost;
global $dbname, $dbtbl,$date_time;

Most of these deal with the database abstraction layer that we haven't discussed yet, so don't worry if you do not understand it. The next bit of the function simply sets up the user supplied and internal variables:

//set login status
$this ->loginstatus=FALSE;
//set variables received from user
$this->errmsg="Your login details could not be found. Please try
//set date time value

The $this->errmsg variable will of course be overridden depending on the kind of error generated. The check_user() function is at the heart of the authorization class. It does the job of checking to see if a user exists:

First we declare a couple of global variables:

function check_user(){
global $userid,$uname,$access,$did,$err,$em;

Then we connect to the database server -- again, don't worry if you don't understand this part, we will get to it a bit later on. Notice that to connect to the database server you will need a URL coming in the form of dbpath that we initialized in the constructor function:

//connect to the db server with the user provided dbpath
$dbcon = new DBAL($this->dbp);

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