GeoIP Country Location – PHP Script
Basically, this PHP script utilizes MaxMind’s free database for determining the country of an IP address.
Download:
Step 1) Get country-redirect.php
Step 2) Get the most recent IP-country database.
Step 3) Extract, then upload both files to the same directory.
Demo: You may see where it thinks you are from.
Once you download the script, go to the end of country-redirect.php to customize its output.
More information
The PHP coding wasn’t written entirely by me. I essentially combined a bunch of classes from MaxMind to make this work. I do not guarantee its functionality on your server. It should work for PHP4-5 at least.
The actual determining of the country is about 99.5% accurate. All AOL users are assumed to be from the United States.
In my case, I find this is helpful for affiliate offers that redirect based on a user’s country. This way (if you are an affiliate), you can select to which offers you’d like to send your international visitors.
Anyway, this should be helpful for providing more relevant content to all of your users.
Popularity: 69%




9 Responses to “GeoIP Country Location – PHP Script”
I’s love to see more stuff written about showing the city also.. There’s a few free scripts that show city also..
@craig m: Yeah, very true. I was keeping this script for a single purpose, though.
hy i install but it showes me blank page
its working now.i just upload GeoIP.dat file as binary mode. Thanks for this
sorry, how redirect to a page?
@sentih: Here’s detailed instructions on how PHP redirects work: http://us2.php.net/manual/en/function.header.php
Can this be made to only look at the United States and geocode the States like Colorado, Florida, Etc. and send the users to a sub domain name if they in Colorado they would be sent to http://co.mydomain.com/
Hi, i installed but a blank page is being shown.
Hi Mike,
I got a blank page as wel. My $_SERVER['REMOTE_ADDR'] variable was a local/network address (192.168. etc). So it could not resolve it’s country, duh! Be sure to run the script with a public address or simply upload the script to a webserver so it receives your public ip-address.
Floris
Leave a Reply