Very Simple Password Protection of a Page

// Bare Bones demo of password protection

<?php
$password = "abc123";
if ($_POST[doddle] == $password) {
        $tell = 1;
} else {
        $tell = 2;
}
if (! is_string($_POST[doddle])) $tell = 0;
?>
<html>
<head><title>A Page that is password protected</title></head>
<body>
<?php if ($tell == 1) { ?>

<h1>The page with all the secrets revealed </h1>

This is the information that has been revealed to you because you
got the password right!<br /><br />Although this is a very simple
demo it shows what you can do with just a few lines of PHP.

<?php } else { ?>

<h1>A Header page</h1>

There is a page hidden under a password at this URL. For this demo only
I will tell you that the password is "abc123" so you can try it out!<br />
<?php if ($tell == 2) print ("<br />YOU GOT THE PASSWORD WRONG<br />"); ?>
<br />
<form method=post>
Please enter password <input type=password name=doddle>
<input type=submit value=go>
</form>

<?php } ?>

<hr />
<a href=http://www.oxmediadigital.com>Cheap Web sites for your business</a>, 2009
</body>
</html>

About Bulent

Yes, my name is Bulent. I am originally from Turkey but now reside in United Kingdom. I have been working as a designer for over 8 years and have been very fortunate to have worked on a wide variety of projects. I have recently developed one of the most succesfull recruitment portal for nearly a million Turkish speaking community in UK within few months we had reached to nearly 65,000 users and stil growing. Thank you for stopping by!

Leave a comment

You must be logged in to post a comment.