-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.php
52 lines (44 loc) · 1.21 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
$is_invalid = false;
if($_SERVER["REQUEST_METHOD"] === "POST")
{
$mysqli = require __DIR__ . "/database.php";
$sql = sprintf("SELECT * FROM user WHERE email = '%s'", $mysqli->real_escape_string($_POST["email"]));
$result = $mysqli->query($sql);
$user = $result->fetch_assoc();
if($user)
{
if(password_verify($_POST["password"], $user["password_hash"]))
{
session_start();
session_regenerate_id();
$_SESSION["user_id"] = $user["id"];
header("Location: index.php");
exit;
}
}
$is_invalid = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>LogIn Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles/index.css">
</head>
<body>
<h1>LogIn Page</h2>
<?php if($is_invalid):?>
<p>Invalid Email or Password</p>
<?php endif; ?>
<form method="post">
<input autocomplete="off" type="email" placeholder="Email" name="email" id="email" value="<?= htmlspecialchars($_POST["email"] ?? "") ?>">
<br><br>
<input autocomplete="off" type="password" placeholder="Password" name="password" id="password">
<br><br>
<button>LogIn</button>
</form>
</body>
</html>