-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
67 lines (62 loc) · 1.58 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
60
61
62
63
64
65
66
67
<?php
include('core/init.inc.php');
$errors = array();
if (isset($_POST['username'], $_POST['password'])) {
if(empty($_POST['username'])) {
$errors[] = 'The username cannot be empty.';
}
if(empty($_POST['password'])) {
$errors[] = 'The password cannot be empty.';
}
if(valid_credentials($_POST['username'], $_POST['password']) === false) {
//log in
$errors[] = 'Username / Password incorrect.';
}
if(empty($errors)) {
$_SESSION['username'] = htmlentities($_POST['username']);
header('Location: protected.php');
die();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD xhtml 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="ext/css/style.css" />
<title></title>
</head>
<body>
<div>
<?php
if (empty($errors) === false) {
?>
<ul>
<?php
foreach($errors as $error) {
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
}
else {
echo 'Need an account ? <a href="register.php">Register here</a>';
}
?>
</div>
<form action="" method="post">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php if(isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="passsword" />
</p>
<p>
<input type="submit" value="Login" />
</p>
</form>
</body>
</html>