Reputation: 49
I have a problem to know IP client run script PHP.
This is my code. work fine in Xampp or Wamp,
function get_client_ip_server() {
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
but when run in Linux server just show IP server. I try many clients by different IP and much simple code but just show IP server again. why?
Upvotes: 0
Views: 67
Reputation: 943569
That will show the IP address that the request arrived at PHP from (which could be a proxy server), unless something along the way adds an additional header saying that the request is being made on behalf of some other client.
In your case, it looks like there is a proxy on your server between your HTTP server and the client, so you are getting the IP address of that proxy.
Upvotes: 1