1. <?php // Script 8.13 - login.php #2
2. /* This page lets people log into the site (in theory). */
3.
4. // Set the page title and include the header file:
5. define('TITLE', 'Login');
6. require('templates/header.html');
7.
8. // Print some introductory text:
9. print '<h1>Login Form</h1>
10. <p>Users who are logged in can take advantage of certain features like this, that, and the other thing.</p>';
11.
12. // Check if the form has been submitted:
13. if ( isset($_POST['submitted']) ) {
14.
15. // Handle the form:
16. if ( (!empty($_POST['email'])) && (!empty($_POST['password'])) ) {
17.
18. if ( (strtolower($_POST['email']) == 'me@example.com') && ($_POST['password'] == 'testpass') ) { // Correct!
19.
20. // Redirect the user to the welcome page!
21. ob_end_clean(); // Destroy the buffer!
22. header ('Location: welcome.php');
23. exit();
24.
25. } else { // Incorrect!
26.
27. print '<p>The submitted email address and password do not match those on file!<br />Go back and try again.</p>';
28.
29. }
30.
31. } else { // Forgot a field.
32.
33. print '<p>Please make sure you enter both an email address and a password!<br />Go back and try again.</p>';
34.
35. }
36.
37. } else { // Display the form.
38.
39. print '<form action="login.php" method="post">
40. <p>Email Address: <input type="text" name="email" size="20" /></p>
41. <p>Password: <input type="password" name="password" size="20" /></p>
42. <p><input type="submit" name="submit" value="Log In!" /></p>
43. <input type="hidden" name="submitted" value="true" />
44. </form>';
45.
46. }
47.
48. require('templates/footer.html'); // Need the footer.
49. ?>