11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 18 • SESSION HANDLERS// Has a session been initiated previously?if (! isset($_SESSION['username'])) {// If no previous session, has the user submitted the form?if (isset($_POST['username'])){$db = new mysqli("localhost", "webuser", "secret", "corporate");?");$stmt = $db->prepare("SELECT first_name FROM users WHERE username = ? and password =?>$stmt->bind_param('ss', $_POST['username'], $_POST['password]);$stmt->execute();$stmt->store_result();if ($stmt->num_rows == 1){}$stmt->bind_result($firstName);$stmt->fetch();$_SESSION['first_name'] = $firstName;header("Location: http://www.example.com/");} else {require_once('login.html');}} else {echo "You are already logged into the site.";}At a time when users are inundated with the need to remember usernames and passwords for everyimaginable type of online service from checking e-mail to library book renewal to reviewing a bankaccount, providing an automatic login feature when the circumstances permit will surely be welcomedby your users.Generating a Recently Viewed Document IndexHow many times have you returned to a web site, wondering where exactly to find that great <strong>PHP</strong>tutorial that you forgot to bookmark? Wouldn’t it be nice if the Web site were able to remember which379

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!