3.4. Building the Login Script
The login application has one main login script that displays and processes the information from the login form. The script is organized into three basic sections:
One section executes the first time the login page is displayed, before the user clicks a button.
Another section executes when the user clicks the Login button.
A third section executes when the user clicks the Register button.
A switch statement controls the script flow based on which button is clicked. The following is an overview of the structure of the script:
switch (Button) case "Login": 1 Test whether the user name is in the database. If not, redisplay the form with an error message. 2 Test whether the password is correct. If not, redisplay the form with an error message. 3 When login succeeds, display the protected Web page. case "Register": 1 Test whether all the fields are filled in. If not, redisplay the form with an error message. 2 Test whether the information is in the correct format. If not, redisplay form with error message. 3 When information is correct, store it in database. 4 When registration succeeds, display the protected Web page. case "default": Display the Login Web Page with blank form fields
The default case executes if neither the Login button nor the Register button are clicked.
Listing 3-3 shows the code for the login application script.
Example 3.3. Login Application Code
<?php /* Program: Login_reg.php * Desc: Main application script for the User Login * ... |
Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.