-
Notifications
You must be signed in to change notification settings - Fork 0
/
secure.php
88 lines (78 loc) · 2.05 KB
/
secure.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="en">
<head>
<title>Password Protection via PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- styling to make the demo look a wee bit better -->
<style>
/* reset */
*{
margin:0;
padding:0;
}
body{
height:100vh;
display:flex;
align-items:center;
justify-content:center;
}
.form-container{
padding:20px;
border:1px solid;
}
.form-row{
margin-bottom:20px;
}
.form-row:last-child{
margin-bottom:0px;
}
.hidden-content-container{
margin-top:50px;
background-color:lightgreen;
border:1px solid;
padding:20px;
}
</style>
</head>
<body>
<!-- centered content -->
<section>
<!-- container for password-entry form -->
<div class="form-container">
<?php
$passErr = "";
$thePassword = "password";
$pass = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["pass"])) {
$passErr = "Password is required";
} else {
$pass = $_POST["pass"];
if($pass != $thePassword){
$passErr = "Incorrect password";
}
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" autocomplete="off">
<div class="form-row">
<label>Password: </label>
<input type="password" name="pass" value="">
<input type="submit" name="submit" value="Enter">
</div>
<div class="form-row">
<?php echo $passErr;?>
</div>
</form>
</div>
<!-- where the hidden content will be injected -->
<?php
if($pass == $thePassword)
{
include("secure.html");
}
?>
</section>
</body>
</html>