How to hide your google ads from certain countries?

ijazzaky

Newbie
Joined
Dec 8, 2012
Messages
13
Reaction score
2
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
 
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
 
Back
Top