Skip to content

Instantly share code, notes, and snippets.

@speedupmate
Created December 6, 2011 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save speedupmate/1438377 to your computer and use it in GitHub Desktop.
Save speedupmate/1438377 to your computer and use it in GitHub Desktop.
GeoIp test
<?php
/**
* PUT THE PATH TO GEOIP DATABASE HERE
*/
$database ='geoip/GeoLiteCity.dat';
try {
require_once('Net/GeoIP.php');
$ipaddress = $_SERVER['REMOTE_ADDR'];
$database = $database;
$geoip = Net_GeoIP::getInstance($database);
$location = $geoip->lookupLocation($ipaddress);
/**
* IF PEAR NET_GEOIP IS INSTALLED AND PHP CAN ACCESS THIS THEN YOU WILL SEE YOUR COUNTRY CODE DETECTED IF NOT THEN YOU SEE ERRORS INSTEAD
*/
echo $location->countryCode.' > CONGRATS IT IS ENABLED';
} catch (Exception $e) {
print_r($e->getMessage());
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment