IP Address Ban?
Hi,
I was wondering if it was at all possible to restrict access to a website from a particular IP address,
ie. if you know someone who you do not want to access your site at all, can you prevent them from opening the page?
Hi,
I was wondering if it was at all possible to restrict access to a website from a particular IP address,
ie. if you know someone who you do not want to access your site at all, can you prevent them from opening the page?
Suzanne posted this at 22:19 — 30th May 2004.
She has: 5,507 posts
Joined: Feb 2000
Only if their IP address is fixed. Most aren't. The best you can do is block a, er, block of addresses and hope for the best. Or require registration for everyone who isn't banned.
Or live with it.
The Dave posted this at 15:01 — 31st May 2004.
They have: 3 posts
Joined: May 2004
Well how would I go about implementing this?
Suzanne posted this at 15:29 — 31st May 2004.
She has: 5,507 posts
Joined: Feb 2000
I'm loathe to recommend how to do something like this -- it will cause you more problems than not if you're trying to block a PERSON. Blocking robots is easier because the IP is static, not rotating. This goes in your .htaccess file.
<Limit GET HEAD POST>
order allow,deny
deny from 127.0.0.1
allow from all
</Limit>
Greg K posted this at 16:52 — 31st May 2004.
He has: 2,145 posts
Joined: Nov 2003
I wrote a script for a company to do something similar. The issue had to do with competition taking new concept ideas off of their site and putting them on their own as their concepts. Luckily the chance of a possible client from the ISP of the competition were small. Someone forwarded the company an e-mail from the competition, so we were able to find their ISP and IP range that ISP used for the area.
I set up a script that gets called from every page, and if the IP address was in that range, it set a variable to be TRUE. Then anywhere on the pages new content was added, I wrote a check to see if that variable was set to be true. If it was, it didn't display the new conent. Therefore, to competiton, the site is the same as when we started tracking them.
I also set up a log that records when they visit. They are gracious enought to contribute at least 1 hit on the statics a day LOL.
Note, in the following code, I changed the IP#'s to be in an invalid range, you would have to adjust the code to test the IP ranges:
<?php
$timestamp = date(\"Y-m-d\") . \"\t\" . date(\"H:i:s\");
$whoisit = $_SERVER['REMOTE_ADDR'];
if ($whoisit == \"\") $whoisit = \"-\";
$thispage = $_SERVER['PHP_SELF'];
$referer = $_SERVER['HTTP_REFERER'];
if ($referer == \"\") $referer = \"-\";
$browser = $_SERVER['HTTP_USER_AGENT'];
if ($browser == \"\") $browser = \"-\";
$itsThem = FALSE;
if (substr($whoisit,0,7) == \"962.99.\")
$itsThem = TRUE;
elseif (substr($whoisit,0,7) == \"916.16.\")
$itsThem = TRUE;
elseif (substr($whoisit,0,7) == \"462.30.\")
$itsThem = TRUE;
if ($avisitor == \"A\")
$itsThem = TRUE;
$logfile = \"ComAccess_\" . date (\"Y-m-d\");
$fh = fopen (\"/usr/home/hide/logs/\" . $logfile, \"a\");
fwrite($fh,
$timestamp . \"\t\" .
$whoisit . \"\t\" .
$thispage . \"\t\" .
$referer . \"\t\" .
$browser . \"\n\");
fclose($fh);
?>
Then in the web pages, the first thing to do is include this file. Then in the page you can do something such as the following to add new content:
<?php
<p>This is original content the competition has already seen and knows about.</p>
if ($itsThem) {
<p>This is the new content you don't want them to see</p>
<!-- Note, be careful if you put PHP code in this section, as you are in an \"IF\" statement here -->
}
<p>This is original content the competition has already seen and knows about.</p>
?>
and for anything you want to change:
<?php
<p>This is original content the competition has already seen and knows about.</p>
if ($itsThem) {
<p>This is the new content you don't want them to see</p>
} else {
<p>This is the old conent you want to leave to not get them suspicious</p>
}
<p>This is original content the competition has already seen and knows about.</p>
?>
Again, I would like to indicate that the company I did this for fully understood that anyone else using their competition's ISP would also see the "old" site, however, the clients they are looking for are not from that area. Luckily the competition uses a "local" ISP, not a national one.
-Greg
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.