Skip to content

Instantly share code, notes, and snippets.

@stormwarning
Last active August 29, 2015 14:04
Show Gist options
  • Save stormwarning/08da064d062168990dd2 to your computer and use it in GitHub Desktop.
Save stormwarning/08da064d062168990dd2 to your computer and use it in GitHub Desktop.
<?php
function geo_ip( $current_ip = 'none' ) {
$current_ip = ( 'none' == $current_ip ? $_SERVER['REMOTE_ADDR'] : $current_ip );
$url = 'http://freegeoip.net/json/' . $current_ip;
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_HEADER, false );
$content = curl_exec( $curl );
curl_close( $curl );
return json_decode( $content );
}
print_r( geo_ip() );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment