<?php
Http://www.cnblogs.com/chengmo/archive/2013/05/29/php.html (please refer to this blog post for details)
1. ' REMOTE_ADDR ' is the remote IP, the default from the TCP connection is the IP of the client. It is the most accurate, but only gets the direct connection to the server client IP.
If the other side through the proxy server online, it is found. Get to the proxy server IP.
such as: A->b (proxy)->c, if C through ' remote_addr ', can only get to the IP of B, get less than the IP of a. */
$ip =$_server[' remote_addr '];
Echo $ip;
2. ' Http_x_forwarded_for ', ' http_client_ip ' in order to be able to get to the most original user IP in a large network, or proxy IP address. Extend the HTTP protocol. Defines the entity header.
Http_x_forwarded_for = Clientip,proxy1,proxy2 all IPs with "," split.
HTTP_CLIENT_IP in the Advanced anonymous proxy, this represents the proxy server IP.
Since the HTTP protocol extends an entity header, and this value is trusted for the incoming side, trust the incoming party to enter it in the regular format.
The x-forwarded-for request header format is very simple:
X-forwarded-for:client, Proxy1, Proxy2
*/
function GetIP () {
if (Isset ($_server[' http_x_forwarded_for ')) {
$realip = $_server[' http_x_forwarded_for ');
} elseif (Isset ($_server[' http_client_ip ')) {
$realip = $_server[' http_client_ip ');
} else {
$realip = $_server[' remote_addr ');
}
return $realip;
}
echo GetIP ();
?>
PHP Get client IP address explained