Use this class to protect your pages with PHP-Sessions and register users while using a MySQL database
This class requires a PHP enabled Apache (virtual) host. I tested this class with PHP 4.3 and MySQL 3.23 on Windows and Linux.
I never tested this class with IIS. If you want to use this class on
Windows / IIS than you have to be sure that the server variable
DOCUMENT_ROOT is available. You can test this while using this code on
your PHP host:
echo getenv("DOCUMENT_ROOT");
If you can't see the document path then this class will not work for you. I'm sure it is possible to change all paths but there is no description about in this manual.
For windows user using this class on a localhost:
You need a mail server program to run some of the scripts (register.php, forgot_password.php and update_user.php)
Database selection
By default the database is not selected with the PHP function mysql_select_db() and the database name is in front of the table name. It's possible that your server doesn't allow the database name inside a query, if this forms a problem then don't use them there and unescape the mysql_select_db() function inside the connect_db() method.
Remember, all example files are full working. The next documentation is only to explain what the methods / variables exactly do.
login.php
Find in this file a form with to text fields
one for the login and one for the password. These entries will be
validated before you can enter the protected area.
I use this page as the target for the account activation process, too. Important methods and variables on this page:
This class can be used in two modes:
If you want to use disable the automatic feature use this variable inside the login script: $my_access->auto_activation = false; // (true/false) or set this boolean inside the class file.
register.php
The register.php file is a regular form with fields for login,
password, e-mail, real name and for extra information. My suggestion
is, removing the last field and using instead the extra info field for
information like: language, register date, customer number etc. To
register a new user only one method required:
Of course there are also standard variables for error messages and to switch messages in different languages (like in the other examples).
update_user.php
Use this example where the user can
update his information like: e-mail, password, extra info and his real
name. The login name is unique and can't be changed. If the user
changed his e-mail address a confirmation mail is send to his new
address and the old one is active until he confirmed the new one. The
user can change his password if he let the password field empty, the
password will not be changed. Methods for this example are:
forgot_password.php
If a user forgot his password and/or
login he can request a reminder mail. Using this file the user fills
the form field with the e-mail address which is used during
registration. After submitting the user get a mail with a link to the
(next) file where you can (re)enter a new password. Only one method is
required (the error message functions as a important option):
activate_password.php
If the user use the link inside the
mail he got, he will reach this page. On this page the user have the
option to enter a new password for his account. After submitting this
new password the user can use it in the login form.
I put the activation string into a session in place of a hidden field.
example.php
Use the code from this file in all pages you
want to protect. I use this file to link to protected pages like
"update_user.php". Notice these methods and variables:
testpage.php
I created this optional page to show how this class take care of previous pages if the user have to login first.
Use this method the same like before, except that you enter these two server variables.
test_access_level.php
This file is an example to test the access level from a user. Find the link on the example.php page.
admin_user.php
This file is also an extenstion, with this file it's possible to change user data like the password (reset), email address, activation status and access level.
Use the example record to admin users (after installation): user: administrator / password: welcome