Files
IWD2-02/INFO-1208 (PHP)/Labs/Lab 9/app/login.php
T

47 lines
1.5 KiB
PHP

<?php
define("TITLE", "User Login");
include("template/header.php");
print("<h2>Login Form<h2>");
$formStart = "<form class='login' action='login.php' method='post'>";
$emailLabel = "<label for='email'>Email:</label>";
$emailInput = "<input type='email' name='email'>";
$passLabel = "<label for='pass'>Password:</label>";
$passInput = "<input type='password' name='pass'>";
$submit = "<input type='submit' name='submit' value='Log In'>";
$formEnd = "</form";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = htmlspecialchars($_POST['email']);
$password = htmlspecialchars($_POST['pass']);
$stickyForm = $formStart .
$emailLabel . $emailInput .
$passLabel . $passInput .
$submit .
$formEnd;
if (!empty($email) && !empty($password)) {
if ((strtolower($email) == 'test@test.com') && ($password == 'test')) {
session_start();
$_SESSION['email'] = $_POST['email'];
$_SESSION['loggedin'] = time();
ob_end_clean();
header('Location: menu.php');
exit();
} else {
print("<p>Email or password is incorrect. Please try again.</p>" . $stickyForm);
}
} else {
print("<p>Email and password are required. Please try again.</p>" . $stickyForm);
}
} else {
print($stickyForm = $formStart .
$emailLabel . $emailInput .
$passLabel . $passInput .
$submit .
$formEnd);
}
include("template/footer.php");