PHP
  Home arrow PHP arrow 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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    (Page 1 of 4 )

    You run a website that is simple enough it doesn't require a database. But your site features certain pages to which you'd like to limit access. Most of the time, that implies using a database to store passwords and usernames. There is an easier way, however. It's less secure, but it involves a lot less coding.
    A downloadable file for this article is available here.

    If you’re using a database with your web application, you already have somewhere to store passwords and usernames, and a method for authenticating visitors.  But what do you do if the complexity or security requirements of your site don’t warrant the use of a database?  There may be times when you want certain pages or areas of your site to be viewable by only particular people. A very simple way of doing this involves using a text file with a password stored in it and creating a page that prompts the visitor to enter a password; if the password matches what is stored in the text file, the user is allowed access to the restricted page, but if it doesn’t, an appropriate message can be displayed before refreshing the start page.

    For further security, you can also encrypt the password that is stored in the text file with a one-way hash so that if the contents of it are discovered somehow, it will still be very difficult to ascertain.  All of this can be done with methods built into PHP. It takes surprisingly little code.

    Before getting started, you’ll need an environment to test and work with PHP in, so you’ll need to have a web server installed and configured for PHP.  Apache works well with PHP and is easily installed and configured, so I’d recommend using this set up. 

    First of all then, you need a page to hold the text box that will receive the password from the visitor and the submit button to send it to your PHP file.  This can be a new page or part of an existing page on your site, whatever you think best.  A block of code as simple as the following should suffice:

    <form name="passwordForm" method="post" action="restricted.php">
      <p>Password:
        <input type="password" name="password">
        <input type="submit" name="Submit" value="Login">
      </p>
    </form>

     

    More PHP Articles
    More By Dan Wellman


       · Hi,This article describes using PHP to read/write to text files and can be used...
       · Are you kidding? What kind of content is that? On which beginner level you have to...
       · Hi,Thanks for the comment, the article is aimed at beginner-level PHP coders,...
       · I think what the person above was trying to say is that maybe you should have the...
       · You're right, I agree; there's no time too early to start learning about security...
       · I find this article very helpful....As a beginner I learned many new things...using...
       · Hello!I´m very thankful for this kind of guides since I´m a total beginner at...
       · r stands for read
       · I did everything exactly but couldnt' get it to work...until I added a semicolon...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





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