PHP
  Home arrow PHP arrow Page 4 - Authentication Scripts for a User Management Application
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Authentication Scripts for a User Management Application
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2008-12-01


    Table of Contents:
  • Authentication Scripts for a User Management Application
  • Script Explained
  • Function Continued
  • The logout script

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Authentication Scripts for a User Management Application - The logout script
    ( Page 4 of 4 )

    The logout script is responsible for ending a session that the user starts when he or she is logged in. It has the following code:


    <?php

    session_start();


    if(isset($_SESSION['uname'])) {

    session_unset();

    session_destroy();

    header("location:login.php" );

    exit();

    }

    else{

    if(!isset($_SESSION['uname'])) {

    //the session variable isn't registered, the user shouldn't even be on this page

    header("location:login.php" );

    exit();

    }

    }

    ?>


    It ends sessions in the following way. First, it checks to see if the username session variable is set after opening the session by calling the session_start() function:


    <?php

    session_start();


    Then the username check is carried out:


    if(isset($_SESSION['uname'])) {


    Next, the session_unset() function is called. This function essentially resets the session array:


    session_unset();


    At this point, the session_destroy() functions are called to end the session:


    session_destroy();


    The session_destroy() function essentially removes the session data from the server, where it is stored in temporary files. Once the session has been destroyed, the user is redirected to the login page:


    header("location:login.php" );

    exit();

    }


    If the username session variable is not set, then the user is also redirected to the login page, since he or she does not have the right to be on the page in the first place: 

    else{

    if(!isset($_SESSION['uname'])) {

    //the session variable isn't registered, the user shouldn't even be on this page

    header("location:login.php" );

    exit();

    }

    }

    ?>

    In the next article, we will take a close look at the login page and the script behind this essential function. See you next week!



     
     
    >>> More PHP Articles          >>> More By David Web
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek