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.
The HTML form collects the username and password and then compares it with the information in the database. This is done through the checkuser() function defined in the login class. Upon successful authentication the username and id are displayed together with the contents of the connection variable. The id of the user is received through the getid() function of the login class; similarly, the username is received through the getname() function. Below is a screenshot of the login test:
There's a couple of things that I haven't done here in terms of security. The first is that I did not hash the passwords that are stored in the database, so please make sure that you implement this safety measure. Use either MD5() or Crypt() to encrypt the passwords. If there are other things that I have not done correctly than please, by all means, correct them before using the code. It is also a good idea to keep both the login application and users table separate from the other applications and databases. The users table should be in a separate database from the rest of the tables.