Miscellaneous

  Home arrow Miscellaneous arrow Page 5 - Writing a Basic Authentication System ...
MISCELLANEOUS

Writing a Basic Authentication System in PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2004-12-24

    Table of Contents:
  • Writing a Basic Authentication System in PHP
  • Storing Passwords
  • Getting the User Login
  • Processing the Login
  • Persisting the Authentication
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Writing a Basic Authentication System in PHP - Persisting the Authentication


    (Page 5 of 6 )

    Once access to a resource has been granted to a user, it's typical for the access privileges to persist for a period of time. PHP sessions offer a nice way to carry information such as authentication throughout a series of pages. This way, a user won't have to provide a user ID and password each time a resource is accessed.

    The validate.php script would initiate a session, set an access token and then redirect the user to the secured document.

    <?php
    if (mysql_fetch_row($result)) {
      
    /* access granted */
      
    session_start();
      
    header("Cache-control: private");
      
    $_SESSION["access"] = "granted";
      
    header("Location: ./secure.php");
    } else
      
    /* access denied &#8211; redirect back to login */
      
    header("Location: ./login.html");
    ?>

    After which each secured resource would continue the session and check for the access token.

    <?php
    session_start
    ();
    header("Cache-control: private");
    if (
    $_SESSION["access"] == "granted")
      
    header("Location: ./secure.php");
    else
      
    header("Location: ./login.html");
    ?>

    I recommend Hermawan Haryanto's tutorial Using Sessions in PHP for more information on working with PHP sessions.

    More Miscellaneous Articles
    More By bluephoenix

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


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