Created
July 24, 2014 05:20
-
-
Save anunay/db951ba66e4d6097484a to your computer and use it in GitHub Desktop.
MaxMind GeoIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** maxmind geoip integration in php */ | |
function get_real_ip() { | |
$ipaddress = ''; | |
if(empty($_REQUEST['ip']) && @$_REQUEST['ip']==""){ | |
if (@$_SERVER['HTTP_CLIENT_IP']) | |
$ipaddress = @$_SERVER['HTTP_CLIENT_IP']; | |
else if(@$_SERVER['HTTP_X_FORWARDED_FOR']) | |
$ipaddress = @$_SERVER['HTTP_X_FORWARDED_FOR']; | |
else if(@$_SERVER['HTTP_X_FORWARDED']) | |
$ipaddress = @$_SERVER['HTTP_X_FORWARDED']; | |
else if(@$_SERVER['HTTP_FORWARDED_FOR']) | |
$ipaddress = @$_SERVER['HTTP_FORWARDED_FOR']; | |
else if(@$_SERVER['HTTP_FORWARDED']) | |
$ipaddress = @$_SERVER['HTTP_FORWARDED']; | |
else if(@$_SERVER['REMOTE_ADDR']) | |
$ipaddress = @$_SERVER['REMOTE_ADDR']; | |
else | |
$ipaddress = 'UNKNOWN'; | |
}else{ | |
$ipaddress = @$_REQUEST['ip']; | |
} | |
return $ipaddress; | |
} | |
include("maxmind-geoip/src/geoipcity.inc"); | |
$gi = geoip_open("maxmind-geoip/GeoLiteCity.dat", GEOIP_STANDARD); | |
$record = GeoIP_record_by_addr($gi,get_real_ip()); | |
$geoipdetails = array(); | |
$country_code = $record->country_code3; | |
$country_region = $record->region; | |
$country_city = $record->city; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment