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

WillMaster > LibraryTutorials and Answers

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!

Protecting Member Areas with Cookies

Some methods of protecting member areas with cookies have better security than other ways. Some member areas need a high level of security. Other's don't.

First, let me mention that storing passwords in cookies is flagrantly insecure. More so now than in the past, with active cookie sniffing connections expected at any public WiFi connection.

One thing that needs to be considered is the type of member data being stored on the server. If credit card information or other highly sensitive data, then do whatever is necessary for the best security that can be coded.

Similarly, if the member area itself contains highly sensitive data.

Without sensitive data in member records or available in member areas, security is less critical.

It is the less critical member areas that this article addresses. Security for highly sensitive data, like banking for example, require the services of an experienced professional online security expert.

Protecting Entire Directories

All files in an entire directory can be protected with a cookie. The cookie can have any value. So long as the cookie exists in the browser, the browser can access files within the directory.

Each directory to be protected has something like this in its .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} !COOKIENAME= [NC]
RewriteRule .* http://example.com/login.php [L]

Replace COOKIENAME with the required cookie name. And replace the login page URL with the correct one.

Cookie Value Keyed To Member Record

For cookie protection at the page level, both the cookie name and the cookie value are validated. For better protection, the cookie value contains a key to the member's data record and also info from the record itself, perhaps the member's email address.

Individual web pages are protected by validating the cookie value. If the data record exists and the data matches, the page load is allowed.

This works for PHP web pages located anywhere in the domain's document directory.

Files containing page elements that need to be protected (videos, spreadsheets) can be put into a cookie protected directory as described in the above "Protecting Entire Directories" section.

It is possible to spoof this cookie. To do the spoof, however, the member data record key and the specific data from the member record need to be known or guessed.

Better Security with Temporary Cookie Values

With this method, the cookie value is still keyed to the member record. The better security comes from the temporary nature of the cookie value.

The cookie value changes every time a member page is loaded into the browser. This makes cookie spoofing hard to do, well nigh impossible for all but the thoroughly skilled.

If a page load presents a cookie with the correct value, two things happen as the browser loads the page:

  1. A cookie with a new value is sent to the browser.

  2. The new cookie value is recorded in the member record.

On the other hand, if a page load is attempted with a cookie value different than expected, these two things happen:

  1. The expected cookie value in the member record is removed (to prevent repeated guessing attempts).

  2. The browser is redirected to the log-in form.

Additional Considerations

Password encryption.

For better security, passwords should be encrypted in the database.

It can be argued that encrypted passwords would prevent password recovery. Yes, that is correct. No unencrypted version of the password should be available anywhere on the server.

Instead of password recovery, let the member specify a new password.

Secure login.

For a short article about login security, see the Login Security article.

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