Single-Page Password Protection

<html>
<head>
<title>Private Page</title>
</head>
<body>

<?php
$password = "phpmac";

if (!isset($_POST['submit'])) {
?>
<form action="" method="POST">
Enter the Password: <input type="password" name="password"><br>
<input type="submit" name="submit">
</form>
<?php
} else {

if ($_POST['password'] == $password) {

?>

Secret content!

<?php
} else {
?>

<form action="" method="POST">
Enter the Password: <input type="password" name="password"><br>
<input type="submit" name="submit">
</form>

<?php
}
}
?>

</body>
</html>

source

Leave a Reply