PEAR Articles
  Home arrow PEAR Articles arrow Page 3 - Completing the Login Script for a PEAR...
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
PEAR ARTICLES

Completing the Login Script for a PEAR CMS
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-10-22

    Table of Contents:
  • Completing the Login Script for a PEAR CMS
  • JavaScript
  • The logout script
  • The CMS

  • 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


    Completing the Login Script for a PEAR CMS - The logout script


    (Page 3 of 4 )

    This script is responsible for logging a user out of the system. In programming terms, the script ends a user session, which is started when the session_start() function is used.

    Below is the code that makes up the script:


    <?php

    session_start();


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

    session_unset();

    session_destroy();

    header("location:login.php" );

    exit();

    }

    else{

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

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

    header("location:login.php" );

    exit();

    }

    }

    ?>

    The code starts by opening a session. This is achieved by calling the session_start() function. This function is used to keep track of session variables such as the ones we set up in the login script. Then we check to see if the session variable called author_name is set:

    <?php

    session_start();


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

    Then you call either the session_destroy() or session_unset() functions (depending on your preference) which empty out the session variables or deletes them and then redirects the user to the login page:


    session_unset();

    session_destroy();

    header("location:login.php" );

    exit();

    }

    If the session variable is not set, then the user is on the wrong page or was not logged in in the first place, in which case the user is also redirected to the login page:

    else{

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

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

    header("location:login.php" );

    exit();

    More PEAR Articles Articles
    More By David Web


     

    PEAR ARTICLES ARTICLES

    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT