Home arrow PHP arrow Page 3 - Building a Logout Class

The Database Tables - PHP

The main function of the logout class is to log out a user and then redirect the user to the login page. On a programmatic level, the logout class terminates and destroys the session variables that the login class created for the user and also logs the exit time to the database. This article will show you how to create a logout class. It is part of a series on application framework components.

  1. Building a Logout Class
  2. Recording the Logout Session
  3. The Database Tables
  4. Testing the Classes
By: Chris Neeman
Rating: starstarstarstarstar / 6
September 05, 2007

print this article



The database table that is used to track user log in and log out is very simple. Below is the SQL to create a table for it:

# Host: localhost
# Database: intranet
# Table: 'logtbl'

CREATE TABLE `logtbl` (
  `logid` int(4) NOT NULL auto_increment,
  `u_id` int(4) NOT NULL default '0',
  `start_sess` datetime NOT NULL default '0000-00-00 00:00:00',
  `end_sess` datetime NOT NULL default '0000-00-00 00:00:00',
  `duration` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`logid`)

It has the following fields:

logid          - Stores a unique number for each new record
u_id           - Stores the user id of the currently logged in user
start_sess - time and date of the user log in
end_sess   - time and date of user log out
duration     - duration in hours, minutes and seconds between start_sess and end_sess date time values

The all important users table contains the usernames and passwords of all the intranet users.  Below is the SQL that will create this table. I've also included sample data for the table. Notice the format in which the email addresses are written. The checkemail() function in the validate class that we discussed in earlier articles checks for this format to verify the validity of a email address:

# Host: localhost
# Database: intranet
# Table: 'users'

CREATE TABLE `users` (
  `uid` int(11) NOT NULL auto_increment,
  `name` varchar(20) NOT NULL default '',
  `sname` varchar(20) NOT NULL default '',
  `upass` varchar(8) NOT NULL default '',
  `access_level` enum('admin','regular') NOT NULL default
  `email` varchar(100) NOT NULL default '',
  `depid` int(2) NOT NULL default '0',
  `isActive` int(2) NOT NULL default '0',
  PRIMARY KEY  (`uid`)

The table has the following fields:

uid          - creates a unique id for every user
name      - stores the name of the user
sname    - stores the surname of the user
upass     - stores the user password
access   - stores the access level either admin or normal
email     - stores the email address of the user
depid     - stores the department id of the user
isactive - sets the user account to either  1 for active or 0 for  inactive

And here's the sample data for the table:

INSERT INTO `users` VALUES (1, 'mubasen', 'gaseb', 'pass',
'admin', 'mubasen.gaseb@damaranet.com', 3, 1);
INSERT INTO `users` VALUES (2, 'dantago', 'nanub', 'sunday',
'regular', 'dantago.nanub@damaranet.com', 1, 1);
INSERT INTO `users` VALUES (3, 'axaro', 'garoeb', 'monday',
'regular', 'axaro.garoeb@damaranet.com', 2, 1);
INSERT INTO `users` VALUES (4, 'koro', 'garises', 'teusday',
'admin', 'koro.garises@damaranet.com', 1, 1);
INSERT INTO `users` VALUES (5, 'saridao', 'taurob', 'thursday',
'admin', 'saridao.taurob@damaranet.com', 2, 1);

>>> More PHP Articles          >>> More By Chris Neeman

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: