PHP
  Home arrow PHP arrow Page 3 - Login and Logout Authentication for a Project 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? 
PHP

Login and Logout Authentication for a Project Management Application
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2008-08-04


    Table of Contents:
  • Login and Logout Authentication for a Project Management Application
  • The HTML Form
  • The Logout Form
  • The 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


    Login and Logout Authentication for a Project Management Application - The Logout Form
    ( Page 3 of 4 )

    The code below does the actual logging out by simply destroying any sessions or session variables that have been set up. First it calls the ob_start() function before including the usual database connection file(dbcon.php) and functions.php.

    <?

    ob_start();

    include "dbcon.php";

    //update the users table

    The ob_start() function allows you to write and execute your scripts as normal but send data to the web browser only at select points. The chief benefit of this is that it enables you to call the session_start() function without having to worry about the dreaded headers already sent error message. We make doubly sure that the session is actually active by checking to see if the name session variable is set.

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

    If so, we first update the users table’s last_login field with today's date, stored in the $td variable. The $td variable is contained in the dbcon.php file that is included at the top. Here are its contents.

    <?

    session_start();

    $title = "Project Management";

    //database connection

    $db = mysql_connect("localhost") or die("Failed to open connection to MySQL server.");

    mysql_select_db("project_management") or die("Unable to select database");

    //set useful variables

    $month_names = array("","January","February","March","April","May","June","July","August",
    "September","October","November",
    "December");

    //set useful variables

    $td = date("Y-m-d");

    $date_time =date("Y-m-d h:i:s");

    ?>

    The $td variable contains today's date in the format year-month-date, which is the format used by MySQL. The update query is run like so:

    $uname =$_SESSION['name'];

    $save = "UPDATE users SET last_login ='".$td."'";

    mysql_query($save);

    Then the sessions are destroyed like so:

    //destroy session

    session_start();

    session_unset();

    session_destroy();

    }else{

    If the name session variable is not set, then we redirect the user to the login page.

    //user is not suppose to be on this page

    //redirect to login page

    header("location:login.php");

    }

    ?>

    The HTML part of the logout script simply displays the "you are now logged out" message and offers the user a login link.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/userauth.dwt.php" codeOutsideHTMLIsLocked="false" -->

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <!-- InstanceBeginEditable name="doctitle" -->

    <title>Project Management::Logout</title>

    <!-- InstanceEndEditable -->

    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

    <link href="Templates/loginstyle.css" rel="stylesheet" type="text/css" />

    </head>


    <body>

    <table width="100%" border="0">

    <tr>

    <td bgcolor="#6699CC" class="headertxt">Project Management:: User Authentication </td>

    </tr>

    <tr>

    <td><!-- InstanceBeginEditable name="main" -->

    <table width="100%" border="0">

    <tr>

    <td width="33%">&nbsp;</td>

    <td width="30%">&nbsp;</td>

    <td width="37%">&nbsp;</td>

    </tr>

    <tr>

    <td colspan="3"><div align="center" class="loginheader"><strong><?php echo $uname.",";?></strong> you are now logged out. </div></td>

    </tr>

    <tr>

    <td colspan="3"><div align="center" class="loginheader">Click <a href="login.php">here</a> to login </div></td>

    </tr>

    </table>

    <!-- InstanceEndEditable --></td>

    </tr>

    <tr>

    <td align="right" class="cright">copyright &copy; 2007 PM </td>

    </tr>

    </table>

    </body>

    <!-- InstanceEnd --></html>




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

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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