PEAR Articles

  Home arrow PEAR Articles arrow Page 3 - Completing the Login Script for a PEAR...
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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    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

    blog comments powered by Disqus

    PEAR ARTICLES ARTICLES

    - Installing PEAR
    - PEAR: an Introduction
    - Managing robots.txt using PHP: Generating Dy...
    - 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


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap