Password Protect Individual Membership Web Pages
Membership software generally restricts access to pages in a certain directory or makes the pages available only while using certain software.
This article shows you how to require a valid log-in to access other web pages in various places on your domain. The pages can be in various directories. Where they are is your decision.
These instructions assume you are using Master Members Only. For instructions on use with other membership software, see the end of this article.
To password protect individual membership web pages (must be .php web pages on most servers), put this PHP code at the top of each page to be protected.
<?php // No text or space may before the "<" character or above this line. // Specify the log-in page URL. $LogInPageURL = "http://example.com/log-in.html"; // Master Members Only cookie name. $CookieName = 'MMOtrack'; if( empty($_COOKIE[$CookieName]) or $_COOKIE[$CookieName] == '0' ) { header("Location: $LogInPageURL"); } ?>
Change the log-in page URL to the URL of the web page where the browser is to be redirected if it does not offer the correct cookie.
If the browser provides the correct cookie, the server provides the page. Otherwise, the browser is redirected to the URL specified in the PHP code.
That is the extent of the implementation.
To test, dump your browser's Master Members Only (or other membership software) cookies. Then, load the protected page with the above PHP code.
You should be redirected to the log-in page.
Log in and try the protected page again.
This time, the server should let the browser have the page.
When the test is passed, you're good to go.
Test every page you implement with this method. It is easy to introduce an error. For example, one little space or other character before the first line of PHP code, or above it, will disable the code. The browser can not then be redirected.
Now you know how to password-protect any of your web pages, wherever they are on the server.
If you are using other membership software other than Master Members Only:
-
Verify it uses a cookie to validate the browser when a page is requested.
-
Verify the cookie is available site-wide (not restricted to a certain directory).
If both of the above are true, make a note of the cookie name. It may be possible to protect individual web pages using your software with the method in this article. Give it a try, substitute the cookie name for the Master Members Only cookie name in the above PHP code.
Will Bontrager