PHP
  Home arrow PHP arrow Page 3 - Private Pages with PHP and Text Files
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

Private Pages with PHP and Text Files
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 15
    2006-02-27


    Table of Contents:
  • Private Pages with PHP and Text Files
  • Creating the main PHP page
  • Using the Password
  • Encryption

  • 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


    Private Pages with PHP and Text Files - Using the Password
    ( Page 3 of 4 )

    To use the password entered into the html form, you need to obtain it and store it in a variable.  As we used the POST method to send the user input to the PHP script, we can use $_POST to get the entered password:

    $password = $_POST["password"];

    We can then simply compare the entered password with the stored password and act accordingly:

      if (empty ($password))
        {
          die ("No password entered");
        }
    elseif ($password != $storedpass)
        {
          die ("Password Incorrect");
        }
    else
      {
        Header("Location: securepage.htm")
      }
    ?>

    The first if statement handles an empty $password variable in case the submit button is clicked when the input box is empty.  The second statement executes the code within brackets if the password the user enters does not match the one that is stored, and outputs a message indicating that the password is wrong.  Finally, if either of the first two conditions are not met, the script concludes that the password must be correct and sends a redirect header to the browser telling it to open the secure HTML page.

    Before this will work, you’ll need to create a text file and place it in the same directory as the PHP file.  It will need to contain the password you intend to use in plain text for now, and should have the filename referenced in the PHP file.  Save all of the files, open the HTML page in a browser and experiment with the form.  The page should work as intended.

    When you enter the correct password, if you get an error message saying:

    “Warning: Cannot modify header information – headers already sent
    by (thepathtoyourphpfile)”

    it means that you need to switch output-buffering to “on” in the php.ini file that is found in your Windows directory.

     



     
     
    >>> More PHP Articles          >>> More By Dan Wellman
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





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