Example #1
0
        header('Location:restricted.php');
    }
}
$missingFields = false;
if (isset($_POST['submit'])) {
    if (isset($_POST['username']) && isset($_POST['password'])) {
        if ($_POST['username'] == "" || $_POST['password'] == "") {
            $missingFields = true;
        } else {
            //All fields set, fields have a value
            $websiteUser = new WebsiteUser();
            if (!$websiteUser->hasDbError()) {
                $username = $_POST['username'];
                $password = $_POST['password'];
                $websiteUser->authenticate($username, $password);
                if ($websiteUser->isAuthenticated()) {
                    $_SESSION['websiteUser'] = $websiteUser;
                    header('Location:restricted.php');
                }
            }
        }
    }
}
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Week 12 Lecture</title>
    </head>
Example #2
0
        header('Location:mailing_list.php');
    }
}
$missingFields = false;
if (isset($_GET['submit'])) {
    if (isset($_GET['username']) && isset($_GET['password'])) {
        if ($_GET['username'] == "" || $_GET['password'] == "") {
            $missingFields = true;
        } else {
            //All fields set, fields have a value
            $websiteUser = new WebsiteUser();
            if (!$websiteUser->hasDbError()) {
                $username = $_GET['username'];
                $password = $_GET['password'];
                $websiteUser->authenticate($username, $password);
                if ($websiteUser->isAuthenticated($username, $password)) {
                    $_SESSION['websiteUser'] = $websiteUser;
                    $lastLogin = date("y-m-d");
                    $websiteUser->lastLogin($username, $password, $lastLogin);
                    $_SESSION["username"] = $username;
                    $_SESSION["password"] = $password;
                    header('Location: mailing_list.php');
                }
            }
        }
    }
}
//Missing username/password
if ($missingFields) {
    echo '<h3 style="color:red;">Please enter both a username and a password</h3>';
}