Last active
February 3, 2021 18:25
-
-
Save justinph/f0fb937d1ee418a45bfb85e91e4bc28a to your computer and use it in GitHub Desktop.
Make wordpress shared password protected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
# send all users w/o this cookie to wall.php | |
RewriteCond %{REQUEST_FILENAME} !(wall\.php|.*\.jpe?g|.*\.m4v|.*\.png|.*\.gif) | |
RewriteCond %{HTTP_COOKIE} !^.*yourfancycookiename.*$ [NC] | |
RewriteCond %{HTTP_USER_AGENT} !^(.*Jetpack.*)$ | |
RewriteRule .* /wall.php [NC,L,R=302] | |
</IfModule> | |
# BEGIN WordPress | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^index\.php$ - [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule . /index.php [L] | |
</IfModule> | |
# END WordPress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function allowAccess() { | |
setcookie( | |
"yourfancycookiename", | |
'1', | |
time()+3600*24*30, // 30 days | |
'/', | |
'your.domain.com', // EDIT THIS | |
true, | |
false | |
); | |
header("Location: /", true, 302); | |
exit(); | |
} | |
if ($_POST && $_POST['dog']) { | |
if (strtolower(trim($_POST['dog'])) === 'fido') { | |
allowAccess(); | |
} else { | |
$message = 'Incorrect answer.'; | |
} | |
} | |
?><!DOCTYPE html> | |
<html lang="en" prefix="og: http://ogp.me/ns#"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Your Blog Name</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Montserrat%3A400%2C700' type='text/css' media='all' /> | |
<meta property="og:title" content="Your Blog Name" /> | |
<meta property="og:description" content="Describe your blog" /> | |
<style type="text/css"> | |
* { box-sizing: border-box;} | |
html{ | |
height: 100vh; | |
overflow: hidden; | |
font-family: Montserrat, "Helvetica Neue", sans-serif; | |
} | |
body { | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
height: 100%; | |
} | |
main { | |
max-width: 50%; | |
text-align: center; | |
} | |
label { | |
display: block; | |
} | |
input[type="text"] { | |
padding: 10px; | |
width: 100%; | |
margin: 5px 0; | |
box-shadow: inset 0 0 3px rgba(0,0,0,0.2); | |
border: 2px solid #ccc; | |
font-size: 1.3rem; | |
} | |
fieldset { | |
text-align: left; | |
border-radius: 3px; | |
margin: 1rem 0; | |
} | |
legend { | |
color: white; | |
background-color: black; | |
padding: .3rem; | |
} | |
#submit { | |
padding: 10px; | |
margin: 10px 0; | |
font-size: 1.3rem; | |
border: 2px solid #666; | |
color: green; | |
border-radius: 3px; | |
text-transform: uppercase; | |
font-weight: bold; | |
font-family: Montserrat, "Helvetica Neue", sans-serif; | |
-moz-appearance: none; | |
-webkit-appearance: none; | |
} | |
#submit:hover { | |
background-color: #eee; | |
} | |
#message{ | |
color: red; | |
font-size: 1.5rem; | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<main> | |
<h1>Answer the following question to enter.</h1> | |
<form action="" method="post"> | |
<?php if ($message) { echo "<p id='message'>$message</p>"; } ?> | |
<fieldset> | |
<legend>Question:</legend> | |
<label for="dog">What is the family dog named?</label> | |
<input type="text" name="dog" id="dog" /> | |
</fieldset> | |
<input type="submit" value="Submit" id='submit' /> | |
</form> | |
</main> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment