Place this at the top of header.php
1: session_start();
2: if(isset($_SESSION['authenticated'])){
3: if($_SESSION['authenticated'] == "yes") {
4: $authenticated = "yes";
5: }
6: else{
7: $authenticated = "no";
8: }
9: }
10: else{
11: $authenticated = "no";
12: }
13:
14: if($authenticated != "yes"){
15:
16: echo <<<EOT
17: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
18: <html>
19: <head>
20: <title>Redirecting</title>
21: <meta http-equiv="REFRESH" content="0;url=http://chatfieldfamily.co.uk/login.php"></HEAD>
22: <BODY>
23: Not authenticated - redirecting...
24: </BODY>
25: </HTML>
26: EOT;
27: exit();
28: }
29: ?>
And save this as login.php
1: <?php
2: session_start();
3: if(isset($_REQUEST['password'])){
4: $password = $_REQUEST['password'];
5: if($password == "password") {
6: $_SESSION['authenticated'] = "yes";
7: $do = "redirect";
8: }
9: else {
10: $do = "incorrect";
11: }
12: }
13: else{
14: $do = "showform";
15: }
16: //done processing
17: if($do == "showform"){
18: $formhtml = <<<EOT
19: <html>
20:
21: <head>
22: <title>Your Site | Login</title>
23: <style type="text/css">
24: body {
25: background: url(images/1.jpg) no-repeat;
26: background-size: 100%;
27: font-family:Verdana, Geneva, sans-serif;
28: }
29: #form {
30: opacity: 0.5;filter:alpha(opacity=50);zoom:1;
31: }
32: #form:hover {
33: opacity: 0.8;filter:alpha(opacity=80);zoom:1;
34: }
35: </style>
36: </head>
37:
38: <body>
39: <div align="center" id="form" class="form"style="margin-top:400px; margin-left:40%; margin-right:40%;; background-color:#000; color:#FFF"><h2>Chatfield Family Login</h2>
40: <form action="http://chatfieldfamily.co.uk/login.php" method="post">
41: Password: <input type="password" name="password"></input><br></br>
42: <input type="submit"></input></form></div>
43:
44:
45:
46: </body>
47:
48: </html>
49: EOT;
50: echo($formhtml);
51: }
52: else if($do == "incorrect") {
53: $formhtml = <<<formhtml
54: <html>
55:
56: <head>
57: <title>Your Site | Login</title>
58: <style type="text/css">
59: body {
60: background: url(images/1.jpg) no-repeat;
61: background-size: 100%;
62: font-family:Verdana, Geneva, sans-serif;
63: }
64: #form {
65: opacity: 0.5;filter:alpha(opacity=50);zoom:1;
66: }
67: #form:hover {
68: opacity: 0.8;filter:alpha(opacity=80);zoom:1;
69: }
70: </style>
71: </head>
72:
73: <body>
74: <div align="center" id="form" class="form"style="margin-top:400px; margin-left:40%; margin-right:40%;; background-color:#000; color:#FFF"><h2>Chatfield Family Login</h2>
75: <form action="http://yoururl/login.php" method="post">
76: <div style="color:#F00" >Incorrect password</div>
77: Password: <input type="password" name="password"></input><br></br>
78: <input type="submit"></input></form></div>
79:
80: //Creating an array of images you want to change between each other
81: var bg = new Array('url(images/1.jpg)', 'url(images/2.jpg)', 'url(images/3.jpg)');
82: var imgIndex=0;
83: //Starting function
84: function changeBg()
85: {
86: $(document).ready(function(){
87: $("div.bg")
88: .fadeTo( 100, 1) //can use any other effect to animate the transition
89: .fadeTo( 100, 1)
90: .css("background-image", bg[imgIndex]);//changing the style
91: });
92: imgIndex = (imgIndex + 1) % bg.length; //looping
93: }
94: setInterval("changeBg()", 1116);//interval between each transition
95:
96: </body>
97:
98: </html>
99:
100: formhtml;
101: echo($formhtml);
102: }
103: elseif($do == "redirect") {
104: echo <<<redirect
105: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
106: <html>
107: <head>
108: <title>Redirecting</title>
109: <meta http-equiv="REFRESH" content="0;url=http://loggedinurl.com"></HEAD>
110: <BODY>
111: Authenticated - redirecting...
112: </BODY>
113: </HTML>
114: redirect;
115: }
116: ?>
see it in use at www.chatfieldfamily.co.uk

Thanks for this! I have one question. Will this also limit search bots to access and index the blog?
RE:Thanks for this! I have one question. Will this also limit search bots to access and index the blog?
Yes this will, I will update the script to allow google bot access (ip addresses) and use a meta-header to prevent it from caching the page.
Update: I know have a modified version which allows google/yahoo/bing bots to access the page. If you want this version email me: webmaster@spiders-design.co.uk
I’m trying to set up my blog in wordpress and I want my page to do what your’s does (single login). How do I or where do I go to create the login.php?
I did the first part ….changed your website to my address but now I’m stuck on step #2.
Thank you!
RE:I’m trying to set up my blog in…
You need to create the file in notepad or any other text editor and upload it o your web histing directory. In addition you need to upload a background image ( you can opy the one on chafieldfamily.co.uk if you want) and save it as 1.jpg in a folder called images or change the script as required.
just tried your method but i do get errors with my login.php.
Parse error: syntax error, unexpected $end in /webspace/13/47942/clubmembers-only.com/wp-content/login.php on line 114
could you please provide us with the example files?
best regards
Tommy
ADMIN REPLY:
Links to source is now provided.
got it … the problem was on my side.
thanks for that script
I have trouble with the redirect on Firefox for mac .
can you help?
EDIT: Firefox on mac has a problem with redirects to fix the problem change the authenticated code from:
authenticated redirecting...to:
I’m also having trouble. First I was experiencing multiple parse and $ errors, but after fixing those, now whenever someone logs in, it just keeps redirecting them back to the login.php!
Where do I change the code?
When someone types in the password, does this just allow them to read the blog? They can’t start editing it, right?
Thanks
Great Job on this script. It works like a charm. Thank you for offering it freely – you are appreciated. Cheers!
I too find that it keeps going back to the login screen.
$_SESSION['authenticated'] gets set to “yes” in the login.php file but when it redirects, it’s no longer yes in the header.php file.
[...] June 30th, 2010 in Web/Tech Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.Powered by WP Greet Box WordPress PluginThere are lots of posts on how to make a password protected WordPress blog. I followed quite a few unsuccessfully (like this one). [...]
[...] To password protect a wordpress 3 blog with a single password use this script: http://www.spiders-design.co.uk/password-protect-wordpress-blog/ [...]