How to block an ip from viewing your adsense ads

Tagged:  

I saw this here i think.
It's a simple way to block certain ip's you might suspect want to give you invalid clicks to get you banned in adsense.
Of course first you have to have a list of ip's you suspect to be ill intentioned, and that isn't very likely to happen in the real world, but if you do, here is what you could do.

Instead of just putting the adsense code in the page you could check with php the ip of the user, and ads from being shown to some ip's.

<?php
$ip = $_SERVER["REMOTE_ADDR"];
$ip_array = array("xxx.xxx.xxx.xx", "xxx.xxx.xxx.xx", "xxx.xxx.xxx.xx", "xxx.xxx.xxx.xx", "xxx.xxx.xxx.xx", "xxx.xxx.xxx.xx", "xxx.xxx.xxx.xx");
?>

<?php
if (in_array($ip, $ip_array)) {
echo 'Blocked Adsense';
}
else {
echo '<Here comes the adsense code>';
}
?>