Prev | Current Page 530 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


$query = "SELECT username FROM users
WHERE username='$username' AND pswd='$pswd'";
$result = mysql_query($query);
// Has the user been located?
if (mysql_numrows($result) == 1)
{
$_SESSION['username'] = mysql_result($result,0,"username");
echo "You've successfully logged in. ";
}
// If the user has not previously logged in, show the login form
} else {
include "login.html";
}
// The user has returned. Offer a welcoming note.
} else {
printf("Welcome back, %s!", $_SESSION['username']);
}
?>
CHAPTER 18 ?–  SESSION HANDLERS 461
At a time when users are inundated with the need to remember usernames and
passwords for every imaginable type of online service, from checking e-mail to library
book renewal to reviewing a bank account, providing an automatic login feature
when the circumstances permit will surely be welcomed by your users.
Generating a Recently Viewed Document Index
How many times have you returned to a Web site, wondering where exactly to find
that great PHP tutorial that you nevertheless forgot to bookmark? Wouldn??™t it be nice
if the Web site were able to remember which articles you read, and present you with
a list whenever requested? This example demonstrates such a feature.
The solution is surprisingly easy, yet effective. To remember which documents have
been read by a given user, you can require that both the user and each document be
identified by a unique identifier.


Pages:
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542