You will be able to track IP addresses from users in different ways... If the user is behind a proxy, you will have a different IP address...
So, as suggested before, the environment variable REMOTE_ADDR represents the IP address of your machine or a proxy. If the environment variable "HTTP_X_FORWARDED_FOR" is set, then you are behind a proxy and you might have a different one... Here's a function that returns the correct IP and proxy IP.
function getIpAddresses() {
$ipAddresses = array();
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ipAddresses['proxy'] = isset($_SERVER["HTTP_CLIENT_IP"]) ? $_SERVER["HTTP_CLIENT_IP"] : $_SERVER["REMOTE_ADDR"];
$ipAddresses['user'] = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
$ipAddresses['user'] = isset($_SERVER["HTTP_CLIENT_IP"]) ? $_SERVER["HTTP_CLIENT_IP"] : $_SERVER["REMOTE_ADDR"];
}
return $ipAddresses;
}
Now, the result of calling this method will always give you a map with the key "user" and, if you are behind a proxy, you can get it through the key "proxy". Here's an example...
$ips = getIpAddresses();
echo "Your IP " . $ips['user'] . "<BR>";
if (isset($ips['proxy'])) {
echo "Your proxy IP is " . $ips['proxy'] . "<BR>";
}
// Running this will give you the following:
// From another machine
Starting the IPs...
Your IP 192.168.48.4
// From the same machine
Starting the IPs...
Your IP 127.0.0.1
// From the same machine with a system proxy
Starting the IPs...
Your IP 127.0.0.1
Your proxy IP is 127.0.0.1
// From another machine with a system proxy
Starting the IPs...
Your IP 192.168.48.4
Your proxy IP is 192.168.48.5