Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The final script in our gift registry application is the first the user sees. It shows the guest a login <form> in which he can enter his username and password. The source of the script is shown in Example 11-5, and its output is shown in Figure 11-2.
When the guest has entered his credentials and clicks on the Log In button, the script is re-requested to validate the credentials. If the username already exists in the people table, the password is validated. If the password matches, the session variable $user is registered with the guest's people_id as its value. Then the header( ) function with the Location: parameter is used to redirect the browser to the presents.php script, along with a welcome message. If the password doesn't match, then the script is re-requested, and an error message is shown.