Skip to content

Commit 189ec09

Browse files
committed
added password protection files; added more information to the readme
1 parent 6fca013 commit 189ec09

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
# php-password-protection-div-demo
2-
A (not super-secure) way to make password protected webpage content with PHP
2+
3+
A (not super-secure) way to make password protected webpage content with PHP.
4+
5+
## In this folder:
6+
- `secure.php` is the container page (will hold the password-entry form and secure content after entering correct password)
7+
- `secure.html` is the secure content (will be injected into `secure.php` after entering correct password)
8+
9+
**NOTE:** For even higher privacy, store `secure.html` file in a not publicly-accessible location.
10+
11+
**NOTE:** This method should not be followed for storing credit cards or other private personal information, but content that should only be visible for users with a given password. This is much more effective than a JavaScript/CSS implementation, but it is not impossible to grab hidden content.

secure.html

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- the raw HTML that should be injected -->
2+
<p>You entered the correct password!</p>

secure.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Password Protection via PHP</title>
5+
6+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
9+
</head>
10+
11+
<body>
12+
13+
<!-- container for password-entry form -->
14+
<div class="form-container">
15+
16+
<?php
17+
$passErr = "";
18+
$thePassword = "password";
19+
$pass = "";
20+
21+
if ($_SERVER["REQUEST_METHOD"] == "POST") {
22+
if (empty($_POST["pass"])) {
23+
$passErr = "Password is required";
24+
} else {
25+
$pass = $_POST["pass"];
26+
if($pass != $thePassword){
27+
$passErr = "Please enter the correct password";
28+
}
29+
}
30+
}
31+
?>
32+
33+
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" autocomplete="off">
34+
Password: <input type="password" name="pass" value="">
35+
<input type="submit" name="submit" value="Enter">
36+
37+
<?php echo $passErr;?>
38+
</form>
39+
</div>
40+
41+
<!-- where the hidden content will be injected -->
42+
<div class="hidden-content-container">
43+
<?php
44+
if($pass == $thePassword)
45+
{
46+
include("secure.html");
47+
}
48+
?>
49+
</div>
50+
51+
</body>
52+
</html>

0 commit comments

Comments
 (0)