I was wondering how to get the ip location and also what OS the visitor is running. Say for instance, I use a Mac so if I would visit this website it would say Mac OS.
So basically something like ipchicken.com has.
I was wondering how to get the ip location and also what OS the visitor is running. Say for instance, I use a Mac so if I would visit this website it would say Mac OS.
So basically something like ipchicken.com has.
To get the client's ip, use the global $_SERVER
array:
$ip = $_SERVER['REMOTE_ADDR'];
To resolve the ip to a hostname you can use gethostbyaddr()
:
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
For the user agent header, which will contain information about the OS and the browser which the client is using, the preferred way is to use the function get_browser()
:
$clientInfo = get_browser(null, true);
var_dump($clientInfo);
... what will give you an array like:
Array
(
[browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
[browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
[parent] => Firefox 0.9
[platform] => WinXP
[browser] => Firefox
[version] => 0.9
[majorver] => 0
[minorver] => 9
[cssversion] => 2
[frames] => 1
[iframes] => 1
[tables] => 1
[cookies] => 1
[backgroundsounds] =>
[vbscript] =>
[javascript] => 1
[javaapplets] => 1
[activexcontrols] =>
[cdf] =>
[aol] =>
[beta] => 1
[win16] =>
[crawler] =>
[stripper] =>
[wap] =>
[netclr] =>
)