Forum Moderators: martinibuster
Problem is I already have several hundred individual adsense ads around my site on static pages. I was hoping for a serverwide solution somehow, without having to recode every page on my site.
It's Linux/Apache server.
Even better would be to block by country domain, e.g. .co.uk or whatever.
if that's what you want, not sure you could just not show ads using it
as Philosopher said, you could easily control the ads using php
you could have the html extension parsed by php, this would allow you to add code but not have to change file extensions. Just a thought, changing technologies is not something I recommend, in this case adding a technology may be an advantage, you would have to look at the cost of implementing it.
something like this would work
<?php
$visitorIP = $_SERVER['REMOTE_ADDR'];
$blockedips = array('123.45.67.89', '123.56.67.89', '123.67.67.89');
if (!in_array($visitorIP,$blockedips)) {
?>
// adsense code here
<?php
}
?>
you paste your adsense code where I marked and then you add the ips you want to block to that array. You would better to store the array in an included file so then at least that could be edited in a sungle location.
remember if you block an ip from someone like AOL then you probably block all of AOL.
That might be especially useful in the dynamic parts of my site (.e.g. the forum).
I should at some point get around to using some include files for the static pages. :-/
Would it be possible to do this to block a range of IPs, using wildcards. e.g. 192.168.*.* or 192.168.?
Would this work?
<?php
$visitorIP = $_SERVER['REMOTE_ADDR'];
$blockedips = array('123.45.', '123.56.', '123.67.67.');
if (!in_array($visitorIP,$blockedips)) {
?>
// adsense code here
<?php
}
?>
I'm also assuming this doesn't violate any Adsense TOS?
and no this wouldn't violate TOS, you are not touching the code, you are just deciding who to serve it to. TThis would be the same as a site that doesn't show ads to logged in users.