-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.php
More file actions
53 lines (48 loc) · 1.48 KB
/
auth.php
File metadata and controls
53 lines (48 loc) · 1.48 KB
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
<?php
session_start();
if (isset($_GET['action']) and $_GET['action'] == 'logout') {
unset($_SESSION['username']);
unset($_SESSION['password']);
unset($_SESSION['logged_in']);
print('Logged out!');
}
$msg = '';
if (isset($_POST['login']) && !empty($_POST['username']) && !empty($_POST['password'])) {
if ($_POST['username'] == 'Dovile' && $_POST['password'] == '1234') {
$_SESSION['logged_in'] = true;
$_SESSION['timeout'] = time();
$_SESSION['username'] = $_POST['username'];
header('Location: index.php');
exit;
} else {
$msg = 'Wrong username or password';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<h2>Enter Username and Password</h2>
</body>
<div>
<?php
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true) {
print('<h1>You can only see this if you are logged in!</h1>');
}
?>
</div>
<div>
<form action="./auth.php" method="post">
<h4><?php echo $msg; ?></h4>
<input type="text" name="username" placeholder="username = Dovile" required autofocus></br>
<input type="password" name="password" placeholder="password = 1234" required>
<button class="btn btn-lg btn-primary btn-block" type="submit" name="login">Login</button>
</form>
</div>
</html>