MENU
Clients IP Address Location
$_SERVER['REMOTE_ADDR'] may not contain the real client’s IP address. It will give you a proxy address for a client connected through a proxy, for example.With the client’s IP address, you can determine its location using a service by http://ipinfo.io.
<!DOCTYPE html>
<html><body>
<pre>
<?php
$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
print_r($details);
?>
</pre>
</body></html>stdClass Object
(
[ip] => 115.133.78.155
[hostname] => No Hostname
[city] => Kota Kinabalu
[region] => Sabah
[country] => MY
[loc] => 5.8626,115.9946
[org] => AS4788 TM Net, Internet Service Provider
[postal] => 88000
)To save space, the following sections abbreviate function prototypes by using a short form for the parameters. Some of the data types are listed below:
| $b : boolean | |
| $i : | integer |
| $f : | float |
| $s : | string |
| $e : | exception |
| $m : | mixed |
| $r : | $resource |
| $arr : | array |
| $f() : | function |
| $cf() : | comparison function |
| $ts : | timestamp in integer |