How To Display GEO Data to Your Users

Status
Not open for further replies.

jeanpaul1979

New member
Dec 30, 2007
471
3
0
Hey guys, I was looking for a Free Geolocation solution today since my old one went into unreliable mode, and I figured why not do a short writeup for other people that might be interested in doing the same... Depending on the campaign this can really help you with conversions.

With Geolocation you can insert states, cities etc. dynamically anywhere within your text. It automatically detects the user's location.

So, here's how you do this...

Download the latest GeoLite City Binary Format here: http://www.maxmind.com/app/geolitecity

Download the GeoIP PHP API here: http://www.maxmind.com/app/php

Extract and upload it to your server and take a look at the sample files of the PHP API to get a feel for how things work. You will probably need to change a few paths and a few other things (see the comment about $_SERVER['REMOTE_ADDR'] in the code example). It helps if you know a bit of PHP, but you can probably figure it out with the help of the samples and my example too.

Here's an example of a finalized script I use to display regions/states:

Code:
<!-- GEO Script-->
<?php
include($_SERVER['DOCUMENT_ROOT'].'/includes/geo_ip/geoipcity.inc');
include($_SERVER['DOCUMENT_ROOT'].'/includes/geo_ip/geoipregionvars.php');
$gi = geoip_open("/home/user/public_html/domain/includes/geo_ip/GeoLiteCity.dat",GEOIP_STANDARD);
// Make sure you replace any static IP with $_SERVER['REMOTE_ADDR'] if you copy the line below from a sample instead
// $_SERVER['REMOTE_ADDR'] returns the IP address of the visitor
$record = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
$region = $GEOIP_REGION_NAME[$record->country_code][$record->region];
geoip_close($gi);
?>
I then insert <?php echo $region; ?> where I want to display the region to my users.

That's it, pretty basic but effective stuff.
 
  • Like
Reactions: Pr0xyhub


Status
Not open for further replies.