Author: Kevin Cadman (Kevin@ZAgamers.za.net)
About this file
This is the documentation for the Authentication class.
If you have any questions or suggestions regarding this class, please
email me at Kevin@ZAgamers.za.net
Level Support. Not just "admin or normal user" but specific level support.
Module Support. Have specific privileges per module, or filename.
The class Authentication is used to simply create "members sections" on pages.
The quick and easy setup:
MAKE SURE YOU HAVE THE FOLLOWING:
The PEAR DB library. (http://pear.php.net)
The Smarty Template System. (http://smarty.php.net)
home.php -> A test "members page." Also demonstrates "logging out."
DB_INFO.php -> Your database details.
authadmin.php -> The file included on "admin" member pages. A demonstration as to how this is done.
auth.php -> The file included on "member pages." (See home.php)
login.php -> The file used to gain Authentication. Demonstrates cookie support too.
common.php -> The file used to include all the Classes. Also used to setup DB on NON Member pages.
Authentication.php -> The main Authentication class.
templates/login.tpl -> The smarty template for the login page.
Here follows a description of the public interface:
function Authentication() - Constructor Funtion
Must be passed the $db object, which is a global variable defined by DB_INFO.php.
Used to Start the Authentication. It is passed the user's inputted username, password and if they're using
cookies. Checks to see if a record exists in the $userTable with the given data.
If so, calls the setAuthed() function.
This will register the relevant sessions and cookies (if need be.)
Used to check the validity of the user's session credentials.
This is used by the auth.php & authadmin.php files. (Please see those files for usage instructions.)
If cookies are used, it will check to see if valid cookies exist. If they do, it'll assign the sessions
with the cookie's data.
Used to get the current user's fields. This is quite handy, as you can add as many fields as you want
to the table. (Example: Telephone, Fax, Address)
Then, to retrieve this information, simply call GetDetail with the field name.
$auth = new Authentication($db);
echo "Your name is".$auth->GetDetail("name");
This is used to kill the sessions & cookies. Used for logout purposed.
You need mySQL. The queries are pretty simple, so I'm sure it'd be pretty straight forward to
port this to another database, as it is using the PEAR DB class. Change your database type in
DB_INFO.php and modify queries accordingly. (I however have no idea why anybody would want to do this.)
CREATE TABLE site_users (
id tinyint(3) NOT NULL auto_increment,
username varchar(255) default '0',
password varchar(255) default '0',
sess_id varchar(255) default '0',
firstname varchar(255) default '0',
lastname varchar(255) default '0',
admin enum('Y','N') default NULL,
email varchar(100) default NULL,
PRIMARY KEY (id)
INSERT INTO site_users
VALUES("1", "admin", "admin", "0", "Admin", "Admin", "Y", "email@example.com");
Defaultly, you may login as admin/admin. (This coincidentally is an admin account!)
Play around with it a bit, I'm sure you'll find it extremely useful for those "Quick and Dirty" sites.
The class doesn't require an exceptional knowledge of PHP, and can be set up in under 5 minutes.
If you have anything to contribute, email me. Kevin@ZAgamers.za.net