SOHO : Small Office Home Office
Freeware - Opensource software tips, tricks, tweaks & fixes for managing, securing, improving the performance of SOHO Desktop, Laptop, Networks

Monday, July 12, 2010

Block Countries with Geoip Lite

This tutorial is for PHProxy users (better than glype )
note: this topic has been discussed again and again and again but i still find users having a hard time installing it so here goes my tutorial (works with shared hosting)
1) Download
GEOIP.inc
and
GEOIP.dat

2)Create a new folder called "geoip" in your phproxy main folder and paste geoip.inc and geoip.dat w/o cap locks inside the geoip folder.





3)Paste this code in index.inc not index.php (people usually paste it in index.php but that can cause unexpected errors like corrupted images and random bugs)

CODE:




Code:
<?php
include('geoip/geoip.inc'); 
$gi = geoip_open('geoip/geoip.dat',GEOIP_STANDARD);
$addr = getenv('REMOTE_ADDR');
$country = geoip_country_name_by_addr($gi, $addr);
geoip_close($gi);
$badcountry = array('Saudi Arabia','China','Iran','Brazil','Hungary','India','United Arab Emirates','Vietnam','Turkey','Pakistan','Israel','Indonesia','Iraq','Egypt');
if(in_array($country, $badcountry))
header('Location: http://YOUR-SITE-GOES-HERE/403.php'); //enter an url or page on your site
?>
and create a costume 403 error.


And you are done

1 comment: