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.
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`) ) TYPE=MyISAM;
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:
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 'regular', `email` varchar(100) NOT NULL default '', `depid` int(2) NOT NULL default '0', `isActive` int(2) NOT NULL default '0', PRIMARY KEY (`uid`) ) TYPE=MyISAM
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