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