Login: Simple (Home Page)

You are now NOT logged in

Explanation

This login system uses PHP sessions. session_start() is called at the top of every page. If the user enters a password then a session variable is created which will have the value true or false depending on whether the password matches the password hardcoded in the script. Content can be shown or not shown to the user based on the value of this session variable.

The function, empty(), is used to test the session variable value because if the session variable has not been declared because the user is not logged in PHP will not raise a variable undefined error.

If the whole page should not be available to the user then the empty() function can be run before the HTML on the page. If the session variable is empty then header("Location...") can be used to direct the user either to the login page or the home page

This login system only allows one password access to the protected parts of the site. It has no mechanism for registering or for resetting the password. It does illustrate the use of sessions and hashing.