Tell Me
 

Logging In

Previous previous|next Next Page

The do_login() function generates the login page. The function detects if the username and password are posted as form parameters. If not, then it displays the login form.

When the login form is submitted, hr.php is requested again. However, the application state will ensure that do_login() is invoked again with the username and password supplied. In this case, do_login() uses the db_connect() database function to authenticate the username and password as valid.

If the username and password are valid, the do_login() function does the following:

Sets the loggedin session variable to indicate that the user has started an application session
Stores the username and password as session state for subsequent database access requests
Uses the PHP header() function to redirect to the hr.php page without parameters causing the department information to be displayed

Note: The login code is simplified for the purposes of this tutorial. Ideally, you would use a single transparent database login and query a database table to authenticate HTTP session login requests.