
Originally Posted by
Chuman
Now I only want to block few countries instead of allowing few countries. I used the following but it doesn't work
<snip>
This works for me, just make sure your file paths are correct (includes/), put this at the top of index.php and browse.php (keeps out hotlinkers too) for glype:
Code:
// THIS IS THE GEOIP COUNTRY BLOCKING CODE
include('includes/geoip.inc'); //this file must exist in your directory
// Uncomment if querying against GeoIP/Lite City.
// include('includes/geoip.inc');
$gi = geoip_open('includes/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('IR', 'CN', 'NG') // redirect them if they suck
if(in_array($country, $badcountry))
header('Location: http://www.youarebanned.info'); //enter a url or page on your site
// END OF COUNTRY BLOCKING CODE
It was posted on another thread somewhere before (maybe even this one).
Bookmarks