-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
59 lines (51 loc) · 1.51 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
53
54
55
56
57
58
59
<?php
include_once("include/db_connection.php");
session_start();
if (isset($_SESSION['uname'])) {
header('Location: overview_appointments.php');
exit;
}
if (isset($_POST['submit'])) {
//Retrieve values (username safe for query)
$uname = mysqli_escape_string($conn, $_POST['uname']);
$password = $_POST['password'];
$query = "SELECT * FROM admin
WHERE uname = '$uname'";
$result = mysqli_query($conn, $query);
$user = mysqli_fetch_assoc($result);
if ($user) {
//Validate password
if (password_verify($password, $user['password'])) {
//Set session variable, redirect & exit script
$_SESSION['uname'] = $user['uname'];
header('Location: overview_appointments.php');
exit;
} else {
$message = "Je gebruikersnaam of wachtwoord bestaat niet!";
}
} else {
$message = "Je gebruikersnaam of wachtwoord bestaat niet!";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<?php if (isset($message)) { ?>
<div><?= $message; ?></div>
<?php } ?>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
<fieldset>
<label for="uname">Gebruikersnaam</label>
<input type="text" name="uname" id="uname" required/>
<label for="password">Wachtwoord:</label>
<input type="password" name="password" id="password" required/>
<input type="submit" name="submit" value="log in"/>
</fieldset>
</form>
</body>
</html>