Forum Moderators: coopster

Message Too Old, No Replies

Hide Adsense to an IP range

Lean mean and efficient script in JSP

         

Alternative Future

9:21 am on Apr 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

Does anyone have a jsp script that will hide a section of the site i.e. adsense from a particular IP range. I am looking for something not too resource heavy.

TIA,

-George

jusdrum

4:27 pm on Apr 22, 2005 (gmt 0)

10+ Year Member



I don't know JSP (and this is a PHP forum), but here's something you can try:

$RemoteIP = $_SERVER['REMOTE_ADDR'];

if (!preg_match("#^20[0-5]#",$RemoteIP))
{
showAds();
}

Modify the regex to your needs, but matching IPs should be fairly simple. The above example would show ads to everyone that is NOT in the 200-205 class A range.

If you want to get more specific, you can do something like:

preg_match("#^123\.123\.123\.[0-2][0-5][0-5]$#",$RemoteIP)

which would match anything in the 123.123.123 class C range