login
Login allows users to login to the website the access other information that not a login has.
<?php
include_once 'Database.php';
include_once 'User.php';
//echo hash('sha512', 'password');
if ($_POST) {
$usersModel = new User();
$user = $usersModel->getByEmail($_POST['email']);
if ($user && password_verify($_POST['password'], $user['password'])) {
setcookie('id', $user['id'], time()+3600*24*30, '/');
setcookie('password', $user['password'], time()+3600*24*30, '/');
header('Location: select.php');
} else {
echo 'cannot login';
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>login</title>
</head>
<body>
<main>
<form action="" method="post">
<p>
<label for="email">Email</label>
<input name="email" type="text" placeholder="Enter email">
</p>
<p>
<label for="password">Password</label>
<input name="password" type="password" placeholder="Enter password">
</p>
<button type="submit">Submit</button>
</form>
</main>
</body>
</html>