Home arrow PHP arrow Page 5 - User Authentication With Apache And PHP

Logging In - PHP

Want to restrict access to certain sections of your Web site?Or customize page content on the basis of user preferences? Or eventrack user movement across your site? Well, the bad news is that you'llneed to learn how to authenticate users on your site. The good news isthat this tutorial has everything you need to get started.

TABLE OF CONTENTS:
  1. User Authentication With Apache And PHP
  2. Back To Basics
  3. The Right Creds
  4. Hidden Costs
  5. Logging In
  6. Rank And File
  7. Heavy Iron
  8. Sock It To Me, Baby!
  9. Time To Live
  10. A Stitch In Time
  11. Closing Time
By: The Disenchanted Developer, (c) Melonfire
Rating: starstarstarstarstar / 59
March 13, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
The alternative approach involves bypassing Apache's HTTP authentication altogether, relying instead on custom programming to perform access control and session management. This allows you to customize both the user interface presented for login, and also the data source used for credential verification.

You can write code for this in any language; I'll be using PHP, since it comes with built-in session management support, which will make things easier.

Let's assume the following directory structure:

/usr/local/apache/htdocs/ index.php login.php error.php inner.sanctum.php
Let's also assume that the file I need to protect is "inner.sanctum.php"

First up, I need to define my custom login form. Here's what I came up with:

<? // index.php - login form ?> <html> <head> <basefont face="Verdana"> </head> <body> <center> <table border="0" cellspacing="5" cellpadding="5"> <form action="login.php" method="POST"> <tr> <td>Username</td> <td><input type="text" size="10" name="f_user"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="10" name="f_pass"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="Log In"></td> </tr> </form> </table> </center> </body> </html>
Here's what it looks like:



Once the user submits this form, the username and password entered will be stored in the form variables $f_user and $f_pass respectively. These variables can be accessed by the PHP-based form processor, coming up on the next page.

 
 
>>> More PHP Articles          >>> More By The Disenchanted Developer, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


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

Dev Shed Tutorial Topics: