Forum Moderators: martinibuster
<?php include("inc/ads.php");?>
-- inc/ads.php :
include("blocked_ips.php");
$ip = $_SERVER['REMOTE_ADDR'];
$ad_client = "<< YOUR PUBLISHER ID >>";
if(in_array($ip,$blocked_ips)) $ad_client="";
// print << ADSENSE CODE... $ad_client ...ADSENSE CONTINUED >>
-- inc/blocked_ips.php :
$blocked_ips = array(
'xx.xx.xx.xx', 'xx.xx.xx.xx', 'xx.xx.xx.xx'
);
Could someone make an example, using an adsense code with publisher Id, but ofcourse changed a little, so that its not real.
There are many ways around this by using some sloppy php coding I'm sure there are some CLEANER ways of doing this but this was the first thing that popped into my head. Oh and don't forget to add your IP that you want to block you can put as many as you wish in these ' and seperate them with commas.
First off the page must be on a php ready server and end with a .PHP rather than .HTM or .HTML
So the url would read like this hxxp://www.myglorioussite.com/myfile.php
Then you ad the following - Note the bold is where you will add the exact Adsense code block that you get from the adsense site:
<?PHP
$blockedips=array('111.111.1111','000.000.000.000','127.0.0.1');
$ip=$_SERVER['REMOTE_ADDR'];
$showad='yes';
$tt=0;
While ($tt<count($blockedips)){
if ($ip==$blockedips[$tt]){$showad='no';}
$tt=$tt+1;
}
if ($showad=='yes'){?>
Then you would ad your adsense code block here
<?php }?>
You can also add this line (after the <?php }?>)if you want people to know that they are missing something.
<?php if ($showad=='no'){print '<font size =5><br>This is where your an Ad would have gone if your IP was not blocked<br></font>';}?>
EDIT: I hope this is what you wanted to do. Just a temporary NOT SHOWING of the ad for those ips.