Single-Page Password Protection

Warning: This article/tutorial is more the 45 days old. As such the information contained within could be, by now, out of date. Please read all information to make sure that this article/tutorial will work with your current version of the Operating System

First let’s build a skeleton.



Private Page


First, we will introduce the $password variable. Set this to anything you like. For the tutorial, we will use “phpmac”.

We will then display a password form if it has not already been submitted.



Private Page

Enter the Password:


So now we have $password set and a form being displayed if it has not yet been submitted. Now, we will add an else to the conditional and inside that else and a second conditional that will compare the user’s input to $password.



Private Page

Enter the Password:

Secret content!


And that’s it. If you would like, you may also display the password form again if it is incorrect. This is shown below:



Private Page

Enter the Password:

Secret content!

Enter the Password:


Leave a Reply

Your email address will not be published. Required fields are marked *