我是博客,并在我的博客中放置了Google广告。我不希望这些广告在某些国家/地区显示我是否可以在我的页面中使用任何其他代码来帮助我实现这一目标。
举个例子,我不想在德国展示广告。任何建议?
答案 0 :(得分:0)
您可以使用http://www.geoplugin.net/
中的APIEG。用PHP
$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".getRealIpAddr());
$country = $xml->geoplugin_countryName ;
if($country != "Germany")
{?>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Horizontal Big Banner -->
<ins class="adsbygoogle"
style="display:inline-block;width:970px;height:250px"
data-ad-client="ca-pub-XXXXXXXXXXX"
data-ad-slot="XXXXXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php
}
//For getting IP Address
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}