The remaining seven functions simply retrieve individual bits of information based on the outcome of the check_user () function. If you go back to the function, you will notice that we stored some global variables and assigned values from the SQL query. Those values can now be retrieved by the program as and when needed:
This function retrieves the user id:
This function retrieves the user name:
This function retrieves the user access level:
Retrieves the error message:
This function retrieves the department id of the user concerned:
This function retrieves the new user id:
This function retrieves the user email address:
These seven functions will be used to set up the sessions for the user at login. The next function simply logs the time and date that the user logged in.
First we set some global variables:
Then we connect to the database server with the database path that I provided:
//connect to the db server with the user provided dbpath
We then build the SQL query. The query simply inserts the date and time of login for a particular user. To make sure that the log in date and time is inserted for the correct user, the userid variable is used. If this userid does not exists, the query will return an error:
$query_ins = "INSERT INTO logtbl SET u_id='".$this->userid."',
The query is then executed, like so:
If the result of the query is false, we store the error message as shown below:
Otherwise, if the result of the query is true, then we collect the new id of the record that we just inserted. This id will then be used when we log out the user:
That covers the login class. Below is an outline of the configuration file for the login class. Some of the database variables that we used in the constructor function are stored here:
Hopefully some of the code in the constructor function will begin to make sense to you. The configuration information above sets up various variables that are used in the login and logout classes.
In the follow-up article will look at the logout class before writing a test application to test the login class. We will also discuss the database tables that are going to store the information about intranet users. Both of these tables have very simple structures, but are very effective in their functions. The logout class will also contain a function to record the time and date that the user is going to log out. We will look at this function in great detail.
blog comments powered by Disqus