โค้ด: เลือกทั้งหมด
<?php
if (getenv(REMOTE_ADDR)=="127.0.0.1")
{
echo "<script>window.location='http://www.sex.com ';</script>";
exit;
}
?>
โหลด geoip.inc and geoip.dat
geoip.inc > http://geolite.maxmind.com/download/geoip/api/php/
geoip.dat > MaxMind - GeoLite Country | Open Source IP Address to Country Database
http://www.maxmind.com/app/geoip_country
โค้ด: เลือกทั้งหมด
<?php
include('geoip.inc'); //this file must exist in your directory
$gi = geoip_open('/your/path/to/GeoIP.dat',GEOIP_STANDARD);
// get the ip of the visitor
$addr = getenv('REMOTE_ADDR');
// translate his ip to a country code
$country = geoip_country_code_by_addr($gi, $addr);
// close the geo database
geoip_close($gi);
$badcountry = array('CN','TR');
// redirect them if they suck
if(in_array($country, $badcountry))
header('Location: http://www.SOMEDOMAIN.com '); //enter a url or page on your site
?>