Using the HTML <form> Environment
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.
![]() |
If the username doesn’t exist, it is added to the
people table along with the user-supplied
password. This allows a new guest to use the system, decide on his
own username and password, and log in. For applications in which
security is important, the usernames and passwords would be added to
the people table by an administrator.
Passwords are
encrypted. The PHP library
function crypt(
)
is a
one-way encryption function that takes two parameters: the string to
be encrypted and a salt. The salt ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
