homepage Welcome to WebmasterWorld Guest from 54.227.40.166
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Google / Google AdSense
Forum Library, Charter, Moderators: incrediBILL & jatar k & martinibuster

Google AdSense Forum

    
My Adsense Code
urwellcome




msg:1439306
 9:57 am on Sep 21, 2005 (gmt 0)

hello, all

I'm a newbie to adsense,totally 20 days up to now. My site is a technical website in two languages. I found there some visitors frequently request my website pages: sometimes using webcopier, sometimes using IE, sometimes using unknown agent, from different Ips. I'm afraid my site will be banned by google for click attacks. I have no time to check server logs, I must work and rest. Anyone have an advice? Your helps is valuable.

Now I'm using such adsense code:


<?php
function ip(){
return ( $_SERVER["HTTP_X_FORWARDED_FOR"]? $_SERVER["HTTP_X_FORWARDED_FOR"] : ( $_SERVER["HTTP_CLIENT_IP"]? $_SERVER["HTTP_CLIENT_IP"] : $_SERVER["REMOTE_ADDR"]) );
}

function adsense_ip_blacklist(){
$a = array(
array(1035666176,1035666431),//ip bound 1
array(-632459264,-632458753),//ip bound 2
...,//ip bound n
);
$ip = ip2long(ip());
foreach($a as $b){
if( $ip>= $b[0] && $ip <= $b[1] )
return true;
}

return false;
}

//
function adsense($w,$h,$ch,$t){
$pttn = "/some-agent/i";
if( preg_match($pttn, $_SERVER['HTTP_USER_AGENT']) adsense_ip_blacklist())
return '';

$color_args = array('google_color_border','google_color_bg','google_color_link','google_color_url','google_color_text');
$arg_num = func_num_args();
if($arg_num > 4){
for($i=4; $i<$arg_num; $i++)
$args .= $color_args[$i-4] .' = "' . func_get_arg($i) .'";'.chr(10);
}
return
'<script type="text/javascript"><!--'.chr(10).
'google_ad_client = "pub-0000000000000000";'.chr(10).
'google_ad_width = '.$w.';'.chr(10).
'google_ad_height = '.$h.';'.chr(10).
'google_ad_format = "'.$w.'x'.$h.'_as";'.chr(10).
'google_ad_type = "'.$t.'";'.chr(10).
'google_ad_channel ="'.$ch.'";'.chr(10).
$args.
'//-->'.chr(10).
'</script>'.chr(10).
'<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
}

function glink($w, $h, $ch, $n){
$pttn = "/some-agent/i";
if(preg_match($pttn, $_SERVER['HTTP_USER_AGENT']) adsense_ip_blacklist())
return '';

if($n == 5)
$n = '_s';
else
$n = '';
$color_args = array('google_color_border','google_color_bg','google_color_link','google_color_url','google_color_text');
$arg_num = func_num_args();
if($arg_num > 4){
for($i=4; $i<$arg_num; $i++)
$args .= $color_args[$i-4] .' = "' . func_get_arg($i) .'";'.chr(10);
}
return
'<script type="text/javascript"><!--'.chr(10).
'google_ad_client = "pub-0000000000000000";'.chr(10).
'google_ad_width = '.$w.';'.chr(10).
'google_ad_height = '.$h.';'.chr(10).
'google_ad_format = "'.$w.'x'.$h.'_0ads_al'.$n.'";'.chr(10).
'google_ad_channel ="'.$ch.'";'.chr(10).
$args.
'//-->'.chr(10).
'</script>'.chr(10).
'<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
}
?>


 

base64




msg:1439307
 11:03 am on Sep 21, 2005 (gmt 0)

As i can see, your code snippet will use "$_SERVER["HTTP_X_FORWARDED_FOR"]" as IP address source (when HTTP_X_FORWARDED_FOR is available). But this thing can be easily spoofed and therefore such IP banning is not bulletproof. Better idea is to check "HTTP_CLIENT_IP" and/or "REMOTE_ADDR" too.
By the way, "HTTP_X_FORWARDED_FOR" field in HTTP request can be not only as one ip address, but as comma separated ip address list too. Example:

"10.2.12.231, 196.28.42.39, 196.28.38.21" - we can see, that first ip address is from private LAN and then there are 2 more ip addresses.

So your code snippet must do some more parsing with "HTTP_X_FORWARDED_FOR" field.

urwellcome




msg:1439308
 1:08 am on Sep 22, 2005 (gmt 0)

Thanks a lots, base64

According to your advice, I rewrited the adsense_ip_blacklist() and removed the redundant ip() function.

thanks again!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Google / Google AdSense
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved