Software, your way.
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!

Web Developer Trick

A web developer at times may need to hide certain things from the public until the content is ready to go live.

There are numerous ways to block access, including login with cookie and allowing only certain IP addresses.

(Using guess-resistant spellings to hide directories or file names often doesn't work. The page may end up being indexed simply because your browser loaded the page. Search results then direct people to the page being "hidden".)

The Trick

The web developer trick described in this article uses an IP address to restrict access. (Your internet connection IP address, not your internet domain's ip address.) No login or cookie-setting software is required.

There are three areas that can be restricted, two addressed here and one at another Willmaster Library page:

  1. A section of a web page When a section of a public web page is being added or revised, the section may be blocked from public view, but allowed privately, until final updates are done.

  2. An entire web page When a particular web page needs to be blocked from pubic view, access to the page can be private until revisions have been finalized or until a grand-opening or other specific date is reached.

  3. Entire directories — This method is generally used when a large portion of a website, or the entire site, is being revamped with new pages residing in a separate directory until it is their time to go live. The method is described at the Uncrackable Directory Access article.

When setting up a part of a web page or an entire web page for blocking from public view, it is prudent to test its effectiveness.

The Tor browser can be used to test because it will use an IP address different than yours. If the web page or section is hidden when accessed by Tor, your block is effective.

Alternatively, if you don't have Tor and don't wish to download it, you can test by changing one digit of the IP address and see if you locked yourself out. Then change it back to the correct IP address to restore your access.

Blocking Part of a Web Page From Public View

This comes in handy when adding something to the page, or revising something, and it still needs tweaks before going live. There is no need to make a separate development page only to block the section from the public until it's ready.

Here is the technique.

<?php if( $_SERVER['REMOTE_ADDR']=='127.0.0.1' ): ?>
[restricted access content]
<?php endif; ?>

To use, change 127.0.0.1 to your IP address.

Your IP address can be obtained at the Get IP Address and User-Agent String page.

$_SERVER['REMOTE_ADDR']=='127.0.0.1' is a comparison test, testing to see if the IP address is equal to 127.0.0.1. The restricted content will be displayed only when the page is accessed with the specified IP address.

If the restricted content needs to be available to more than one IP address, repeat the comparison test for each IP address and put the word "or" between the tests. Example:

<?php if( $_SERVER['REMOTE_ADDR']=='127.0.0.1' or $_SERVER['REMOTE_ADDR']=='1.127.127.127' ): ?>
[restricted access content]
<?php endif; ?>

To use, change 127.0.0.1 and 1.127.127.127 to the IP addresses that shall have access.

Blocking an Entire Web Page From Public View

Restrict an entire web page to only one IP address with this one line of PHP code. Put the code at the top of the page.

if( $_SERVER['REMOTE_ADDR']!='127.0.0.1' ) { exit; }

To use, change 127.0.0.1 to your IP address. Suddenly, only that one IP address can successfully access the page.

$_SERVER['REMOTE_ADDR']!='127.0.0.1' is a comparison test, testing to see if the IP address is equal to 127.0.0.1. The page will exit unless the IP address is the same as the one specified.

If the page needs to be available to more than one IP address, repeat the comparison test for each IP address and put the word "or" between the tests. Example:

if( $_SERVER['REMOTE_ADDR']!='127.0.0.1' or $_SERVER['REMOTE_ADDR']!='1.127.127.127' ) { exit; }

To use, change 127.0.0.1 and 1.127.127.127 to the IP addresses that shall have access to the page.

You now know how to employ the web developer trick that uses one or more IP addresses to restrict viewing of an entire web page or a portion of a web page. See Uncrackable Directory Access to restrict an entire directory with IP addresses.

(This article first appeared with an issue of the Possibilities newsletter.)

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