PHP
  Home arrow PHP arrow Page 2 - Application Framework Components: Logi...
Dev Shed Forums 
Administration  
AJAX  
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 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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? 
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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Application Framework Components: Login/Logout - Login Class Functions


    (Page 2 of 4 )

    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->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;
    }

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

    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


     

       

    PHP ARTICLES

    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...
    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery





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