HomePHP Page 3 - User Authentication with patUser (part 1)
Dump Truck - PHP
Need to add authentication to your PHP-based Web application? Getit done in a jiffy with patUser, a PHP class which makes it possible torapidly add powerful user management capabilities to your Web application.
Now that the hard sell is over and you're (hopefully) all set up with patUser, let's get things started. The first thing you need to do is set up a MySQL database to hold your user data - this database will be used by patUser to perform its various tasks.
The patUser distribution comes with an SQL dump file which you can use to create the necessary tables - you'll find it in the "sql/" directory of the distribution, and it looks something like this:
# Table structure for table 'groups'
CREATE TABLE groups (
gid int(11) NOT NULL auto_increment,
UNIQUE gid (gid)
# Table structure for table 'permissions'
CREATE TABLE permissions (
id int(11) DEFAULT '0' NOT NULL,
id_type enum('group','user') DEFAULT 'group' NOT NULL,
# Table structure for table 'usergroups'
CREATE TABLE usergroups (
uid int(11) DEFAULT '0' NOT NULL,
gid int(11) DEFAULT '0' NOT NULL
# Table structure for table 'users'
CREATE TABLE users (
uid int(10) unsigned NOT NULL auto_increment,
username varchar(20) NOT NULL,
passwd varchar(20) NOT NULL,
nologin tinyint(1) DEFAULT '0' NOT NULL,
count_logins int(10) unsigned DEFAULT '0' NOT NULL,
count_pages int(10) unsigned DEFAULT '0' NOT NULL,
time_online int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY username (username)
Each of the tables above plays an important role in the
The "users" table stores information about each user in the system - the user's login name and password, email address, and date of first and last login. Each user in this table is identified by a unique user ID.
patUser allows you to organize users into groups - the "groups" table stores a list of these groups. As with users, each group has a name and a unique group ID.
The "usergroups" table connects the records in the "users" and "groups" table together, specifying which users belong to which groups. patUser groups are not exclusive - a user may belong to more than one group at a time.
The "permissions" table makes it possible to assign permissions for a user or group. These permissions can be used to restrict user activities on a page-by-page basis.
It's important to note, at this stage, that although the developers of patUser recommend using the schema above, there is no restriction on you, as a developer, creating and using your own set of tables. patUser's developers are well aware that different applications have different requirements and the schema above may not be suitable for all needs; therefore, they have designed the patUser library to be flexible enough for use with other, custom schemas as well (more on this shortly).