Logging In and Logging Out
In Chapter 7, “Cookies and Sessions,” I wrote many versions of the login.php and logout.php scripts, using variations on cookies and sessions. Here I’ll develop standardized versions of both that stick to the practices of the whole application.
To write login.php:
1. | Create a new document in your text editor (Script 12.7).
<?php # Script 12.7 - login.php |
2. | Require the configuration file and the HTML header.
require_once ('includes/config.inc'); $page_title = 'Login'; include ('includes/header.html'); |
3. | Check if the form has been submitted, require the database connection, and validate the submitted data.
if (isset($_POST['submit'])) { require_once ('../mysql_connect.php'); if (empty($_POST['username'])) { ... |
Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide 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.