
These PHP scripts demonstration a way to implement a user login area for a PHP based web site. This login mechanism has the following features:
Click here for a demo of it working.
Click here to download the files (tgz).
These scripts are implemented in a very modular fashion to reduce the number of variables that would have to be changed to implement for your site, which means that there is more than you might initially think.
Here are all the files that are involved.
This script contains a selection of global variables for use across all the scripts.
This script gives us a connexion to the database, in this case we are using MySQL.
The main script which checks user name and password entered in login.xhtml, validates it against values in database, creates a session key and sets this both in the database against the users record, and in a cookie. Also handles logout by invalidating cookie.
HTML template for the login page, that's all it is! Calls login.php.
This file checks the login and password entered by the user and makes sure that they match the value set in the cookie and that this in turn matches the database. Would be included in any page needing authentication before viewing.
A home page with nothing on it, shows the use of the file authen.php to validate the user.
Generic HTML page template for displaying error messages, takes $task and $error parameters.
And finally a bit of SQL for creating a table called 'users' with some suggested fields for storing their information.