Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Development and Maintenance

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

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:

  1. Verify it uses a cookie to validate the browser when a page is requested.

  2. 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

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC