Home.
Page 2.
Page 3.
Page 4.
Protected pages

This is an example of a WP site on which some pages are protected by a password, using PHP code.

 

When any protected page is first accessed, it is replaced instead by a login page.  If the password is correct, the protected content is shown.  After that, all protected pages are available to view.

 

 

 

Login page

 

The site has a Login page, “loginpage.php”.  It is excluded from navigation, and has a login form and some PHP code in it.

 

This page is ‘included’ in each protected page when it is accessed.  So all of its code and the form become part of the protected page.  The code works out whether to show the form or to show the protected stuff.

 

You can change the form in WP to suit your own preferences.  Just make sure that the button is named ‘login’ and the password text box is named ‘pword’.  You may well want to set the text box as password entry, so that the characters are not displayed as they are typed.

 

There is one critical line of code at the very end of the page.  It ‘exits’ so that the protected stuff is not displayed.

Protected pages

 

Each protected page must have a .php file name.

 

The only other thing is to go into code view and add one line of PHP right at the top.  This is the one that includes the login page.

 

Look in “Page 2” on this site to see the code.

Password list

 

The list of passwords is kept in a separate ‘HTML page’ on the site (‘pwlist.php’).  This is so that you can change the passwords by uploading just that one file if necessary.