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? 
Google.com  
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

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek