Skip to content

Instantly share code, notes, and snippets.

@bespr
Created January 22, 2017 14:08
Show Gist options
  • Save bespr/9773e035dba2324495a23f8cfe2956ea to your computer and use it in GitHub Desktop.
Save bespr/9773e035dba2324495a23f8cfe2956ea to your computer and use it in GitHub Desktop.
<?php
/**
* Very simple password protectetion for very simple php web pages
*/
$accessWord = 'nameOfMyGirlfriendOrDaughterWhereEsAreReplacedByThrees';
if (!isset($_COOKIE['accessWord']) || $_COOKIE['accessWord'] !== md5($accessWord)) {
if (isset($_POST['accessWord']) && trim($_POST['accessWord']) === $accessWord) {
setcookie('accessWord', md5($accessWord), time() + (7 * 24 * 3600));
} else {
echo '<meta charset="utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
echo '<style>';
echo 'html { font-size: 20px; line-height: 1.5em; box-sizing: border-box; }';
echo '*, *:before, *:after { box-sizing: inherit; }';
echo 'input { font-size: 20px; line-height: 2.5em; padding: 0 0.5em; display: block; margin-bottom: 0.5em; }';
echo 'input[type="submit"] { padding: 0.5em; }';
echo '</style>';
echo '<h1>Please enter accessword</h1>';
echo '<form method="post" action="">';
echo '<input type="password" name="accessWord" />';
echo '<input type="submit" value="Send" />';
echo '</form>';
exit;
}
}
// continue here the rest of your php code. Remove above when there is no need for password protection any longer
?>
<h1>Hi, welcome on my web site</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment