1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to hide your google ads from certain countries?

Discussion in 'White Hat SEO' started by ijazzaky, Oct 26, 2013.

Tags:
  1. ijazzaky

    ijazzaky Newbie

    Joined:
    Dec 8, 2012
    Messages:
    13
    Likes Received:
    2
    Occupation:
    Social media marketer
    Location:
    colombo
    Home Page:
    HOW TO HIDE YOUR GOOGLE ADS FROM CERTAIN COUNTRIES?

    I am curious to know if there's any way to stop showing my google ads from certain countries?? It will be great information if someone kindly tell me. Best Regards
     
  2. gsy159

    gsy159 Power Member

    Joined:
    Apr 29, 2011
    Messages:
    663
    Likes Received:
    159
    Code:
    
    <?PHP
    
    [COLOR=#00008B]function[/COLOR] visitor_country()
    {
        $client  = [COLOR=#800000]@$_SERVER[/COLOR][[COLOR=#800000]'HTTP_CLIENT_IP'[/COLOR]];
        $forward = [COLOR=#800000]@$_SERVER[/COLOR][[COLOR=#800000]'HTTP_X_FORWARDED_FOR'[/COLOR]];
        $remote  = $_SERVER[[COLOR=#800000]'REMOTE_ADDR'[/COLOR]];
        $result  = [COLOR=#800000]"Unknown"[/COLOR];
        [COLOR=#00008B]if[/COLOR](filter_var($client, FILTER_VALIDATE_IP))
        {
            $ip = $client;
        }
        elseif(filter_var($forward, FILTER_VALIDATE_IP))
        {
            $ip = $forward;
        }
        [COLOR=#00008B]else[/COLOR]
        {
            $ip = $remote;
        }
    
        $ip_data = [COLOR=#800000]@json_decode[/COLOR](file_get_contents([COLOR=#800000]"http://www.geoplugin.net/json.gp?ip="[/COLOR].$ip));
    
        [COLOR=#00008B]if[/COLOR]($ip_data && $ip_data->geoplugin_countryName != [COLOR=#00008B]null[/COLOR])
        {
            $result = $ip_data->geoplugin_countryName;
        }
    
        [COLOR=#00008B]return[/COLOR] $result;
    }
    
    if(visitor_country="UK")
    {
    //if from the UK don't show ads
    }
    else
    {
    //show ads
    }
    
    
    ?>
    Here are some other examples, get the right country names, http://www.geoplugin.com/examples