Last active
December 5, 2017 13:38
-
-
Save pkdavies/099fba0f262a2b25b3436cdfeddab3c9 to your computer and use it in GitHub Desktop.
MaxMind GeoIP test
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
<h1>GEO IP Test</h1> | |
<h2>Info</h2> | |
<pre><?php | |
$cst = array( | |
'GEOIP_COUNTRY_EDITION' => GEOIP_COUNTRY_EDITION, | |
'GEOIP_REGION_EDITION_REV0' => GEOIP_REGION_EDITION_REV0, | |
'GEOIP_CITY_EDITION_REV0' => GEOIP_CITY_EDITION_REV0, | |
'GEOIP_ORG_EDITION' => GEOIP_ORG_EDITION, | |
'GEOIP_ISP_EDITION' => GEOIP_ISP_EDITION, | |
'GEOIP_CITY_EDITION_REV1' => GEOIP_CITY_EDITION_REV1, | |
'GEOIP_REGION_EDITION_REV1' => GEOIP_REGION_EDITION_REV1, | |
'GEOIP_PROXY_EDITION' => GEOIP_PROXY_EDITION, | |
'GEOIP_ASNUM_EDITION' => GEOIP_ASNUM_EDITION, | |
'GEOIP_NETSPEED_EDITION' => GEOIP_NETSPEED_EDITION, | |
'GEOIP_DOMAIN_EDITION' => GEOIP_DOMAIN_EDITION, | |
); | |
foreach ($cst as $k=>$v) { | |
echo $k.":\t\t".geoip_db_filename($v)." ".(geoip_db_avail($v) ? "\tAvailable" : '').'<br>'; | |
} | |
?></pre> | |
<hr /> | |
<h2>Fixed Ireland IP test (pingdom EU6):</h2> | |
<?php | |
$ip = '52.48.244.35'; | |
$record = geoip_record_by_name($ip); | |
echo "The {$ip} has a country is {$record['country_name']} and your city is {$record['city']}."; | |
?> | |
<hr /> | |
<h2>Fixed host test:</h2> | |
<?php | |
$host = 'office.juicymedia.co.uk'; | |
$record = geoip_country_code_by_name($host); | |
if ($record) { | |
echo "The host {$host} is located in: " . $record; | |
} | |
?> | |
<hr /> | |
<h2>User Host Check</h2> | |
<?php | |
$ip = $_SERVER['REMOTE_ADDR']; | |
$record = geoip_country_code_by_name($ip); | |
echo "Your country is {$record['country_name']} and your city is {$record['city']}."; | |
?> | |
<h2>Allowed Check</h2> | |
<?php | |
// detect user IP | |
$user_ip = $_SERVER['REMOTE_ADDR']; | |
$country_code = geoip_country_code_by_name($user_ip); | |
$disallowed_array = array("GR","RU","KP","KR","KW","LB","SA","NZ","BH"); | |
//$country_code = "RU"; | |
// lookup country code in our disallowed list | |
if (in_array($country_code, $disallowed_array)) { | |
// hide | |
echo "NOT ALLOWED"; | |
} else { | |
// show | |
echo "ALLOWED TO SEE IT"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment