PHP tip of the week: Getting IP addresses | 2 Comments
Posted in Code on 2nd December 2004, 1:07 pm by Stuart
Extracting the gateway IP address is straightforward:
$ip = $_SERVER['REMOTE_ADDR'];
To obtain the hostname of the gateway IP address just do the following:
$hostname = GetHostByName($_SERVER['REMOTE_ADDR']);
To get the local IP address of your user can sometimes be useful too. Here’s how:
$localip = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'];
