/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<? function geoip($ip = false, $api_key = 'cfea6a359ca8f852da3914055958db09bbcc63d4443b9ad21724dc3a9e8b4295'){ if(!$ip) $ip = $_SERVER['REMOTE_ADDR']; //you can get your own api key here: http://ipinfodb.com/register.php //this function attempts to call via curl, but will fall back to file_get_contents //if curl is not available. $url = "http://api.ipinfodb.com/v3/ip-city/?key={$api_key}&ip={$_SERVER['REMOTE_ADDR']}&format=json&callback="; }else{ } return true; } return false; } // Example usage of the function below: if(geoip()): ?> is from idaho, or colorado. <? else: ?> nope not form idaho, or colorado. <? endif; ?>