This Tutorial explains how to install mod_geoip for Apache2 On Debian Lenny .
We Assume That You Already Have Apache2 As Already Discussed Here
To install mod_geoip
apt-get install libapache2-mod-geoip
Then with your favourite editor open /etc/apache2/mods-available/geoip.conf
and uncomment GeoIPDBFile , so that it looks similar to
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
Next we restart Apache2
/etc/init.d/apache2 restart
Yeah ! you have installed mod_geoip.
for testing it we create a php file with the below code in it..
<html> <head> <title>Your Country</title> <head> <body> <? $country = getenv(GEOIP_COUNTRY_NAME); echo "Your country : $country"; ?> </body> </html>
You can see it in action Here
Uses :
1. Country Based Redirection :
<?php $country_code = ( !empty( $_SERVER['GEOIP_COUNTRY_CODE'] ) ) ? $_SERVER['GEOIP_COUNTRY_CODE'] : 'IN'; header( 'Location: http://www.vpsgeek.info/country/'.strtolower( $country_code ).'/' ); exit; ?>
The Above Code Redirects the users based on their country to a respective directory created for that country users..
You can see it in action Here
It will redirect to wjunction.com/country/yourcountry/
its only for demo purpose !
2. Geo Targetted ads:
this code first detects the visitor’s country code, then using simple if else condition,it will echo out the required ads, you can edit it to your needs.
<?php $country = getenv(GEOIP_COUNTRY_CODE); if ($country=="US") echo "USA ADS"; else echo"hey ! no ads for you !"; ?>
You can see it in action Here
{ 1 trackback }
{ 5 comments… read them below or add one }
thanks
@ scenekid
you are welcome
thanks for commenting
wow
uploaded the post with some uses of mod_geo_IP
we can also use this to block certain countries from visiting our websites .
great post as usual!