Tip: don't show the ads to yourself

Discussion in 'AdSense' started by w3bmistress, Apr 19, 2006.

  1. courtney

    courtney Peon

    Messages:
    99
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #21
    I wish there was some way to see ads on my site, but not have them count as impressions. It would make sense for webmasters, and Google would benefit too since we all make more money when ad relevancy is optimized.
     
    courtney, Apr 22, 2006 IP
  2. tonyinabox

    tonyinabox Peon

    Messages:
    1,988
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #22
    above article is just cool!
     
    tonyinabox, Apr 22, 2006 IP
  3. khin007

    khin007 Banned

    Messages:
    670
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #23
    hi i have a static ip .. does this helps me?
     
    khin007, Apr 22, 2006 IP
  4. w3bmistress

    w3bmistress Well-Known Member

    Messages:
    145
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #24
    if you have a static IP .. yes it helps..

    yeah.. a really good article. I like the idea of adding the extra code for testing.
     
    w3bmistress, Apr 23, 2006 IP
  5. Talktechno

    Talktechno Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #25
    where bouts does tht code go exactly? isit just above the adsense script?

    thnks for tht tip :D was lookin for summin like tht
     
    Talktechno, Apr 25, 2006 IP
  6. mariush

    mariush Peon

    Messages:
    562
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #26
    
    <?
    
    // tells getip() if one of the ips it detects is valid or not.
    
    function validip($ip)
    {
    if (!empty($ip) && ip2long($ip)!=-1)
     {// reserved IANA IPv4 addresses
      // http://www.iana.org/assignments/ipv4-address-space
    	$reserved_ips = array (
    	 array('0.0.0.0','2.255.255.255'), array('10.0.0.0','10.255.255.255'),
    	 array('127.0.0.0','127.255.255.255'), array('169.254.0.0','169.254.255.255'),
    	 array('172.16.0.0','172.31.255.255'), array('192.0.2.0','192.0.2.255'),
    	 array('192.168.0.0','192.168.255.255'),	array('255.255.255.0','255.255.255.255'));
      foreach ($reserved_ips as $r)
    	{	$min = ip2long($r[0]); $max = ip2long($r[1]);
    		if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
    	}
    	return true;
    	}
    	else return false;
    }
    
    // detects the user's ip
    
    function getip()
    {
    global $HTTP_SERVER_VARS;
    if (validip($HTTP_SERVER_VARS['HTTP_CLIENT_IP'])) return $HTTP_SERVER_VARS['HTTP_CLIENT_IP'];
    	elseif ($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']!="")
    	{
    		$forwarded=str_replace(",","",$HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']);
    		$forwarded_array=split(" ",$forwarded);
    		foreach($forwarded_array as $value)	if (validip($value)) return $value;
    	}
    	return $HTTP_SERVER_VARS['REMOTE_ADDR'];
    } 
    
    function ShowAdsense()
    {
    // return 1; // uncomment this in order to see ads no matter what ip detects.
    
    $detectedip = getip();
    
    // repeat this block, only changing $testip if you have several ip's
    $testip="127.0.0.1";
    if (substr($detectedip,0,strlen($testip))==$testip) return 0;
    
    $testip="87.100.3.";  // <-- works on ip ranges 
    if (substr($detectedip,0,strlen($testip))==$testip) return 0;
    
    return 1;
    }
    
    ?>
    
    PHP:
    I'm using the code above, it's placed in a php file which is connected to the other php files using the include or require_once statement.

    You can then use :

    
    if (showAdsense()==1) { // show the ad }
    
    PHP:
    It's a bit more complex because I have two or three different IP classes and I'm actually blocking an IP class ( see the second block in ShowAdsense )
     
    mariush, Apr 25, 2006 IP