Directory structure
Lets take a look at how we are going to set up our files for this application. For this example we will use the following directory structure and files:
/ <-- public root
- account.php <-- Will serve as our protected area
- authUtils.php <-- Contains necessary authentication resources and functions
- common.inc.php <-- Groups common files together and checks for authentication existance
- config.php <-- Sets configuration constants required by other functions
- login.php <-- Displays and processes user login form
- logout.php <-- Used to terminate the users session
- register.php <-- Displays and processes user registration form
- reset.php <-- Allows user to reset their password
Database Table
Now lets create a database table that can be used to store the users information. For this example we will use just the minimum necessary items that I feel you should include. For a practical application you can include as many colums as you find necessary for your needs. Here is the query used to create the table used in this example:
CREATE TABLE `users` (
`user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(25) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(32) NOT NULL,
`first_name` varchar(30) NOT NULL,
`last_name` varchar(45) NOT NULL,
`last_login` datetime NOT NULL,
UNIQUE KEY `user_id` (`user_id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `username` (`username`)
);
This table allows a custom unique username and allows only one user per email address. We will be accomplishing account verification by generating a password for the user and emailing it to them.
Now lets take a look at setting up the database and site configuration file!