Get an IP address function through complex judgments and counts
Copy CodeThe code is as follows:
function GetIP () {
if (getenv (' http_client_ip ')) {
$ip = getenv (' http_client_ip ');
}
ElseIf (getenv (' http_x_forwarded_for ')) {
$ip = getenv (' http_x_forwarded_for ');
}
ElseIf (getenv (' http_x_forwarded ')) {
$ip = getenv (' http_x_forwarded ');
}
ElseIf (getenv (' http_forwarded_for ')) {
$ip = getenv (' http_forwarded_for ');
}
ElseIf (getenv (' http_forwarded ')) {
$ip = getenv (' http_forwarded ');
}
else {
$ip = $_server[' remote_addr ');
}
return $IP;
}
The simplest example of getting an IP address code
Copy CodeThe code is as follows:
$reIP =$_server["REMOTE_ADDR"];
Echo $reIP;
PHP's algorithm for acquiring IP
Copy CodeThe code is as follows:
if (getenv (' http_client_ip ')) {
$onlineip = getenv (' http_client_ip ');
} elseif (getenv (' http_x_forwarded_for ')) {
$onlineip = getenv (' http_x_forwarded_for ');
} elseif (getenv (' remote_addr ')) {
$onlineip = getenv (' remote_addr ');
} else {
$onlineip = $HTTP _server_vars[' remote_addr ');
}
Echo $onlineip;
Can be separated from the intranet and external website IP address acquisition Program
Copy CodeThe code is as follows:
function Getip_out () {
$ip =false;
if (!empty ($_server["Http_client_ip")) {
$ip = $_server["Http_client_ip"];
}
if (!empty ($_server[' http_x_forwarded_for ')) {
$ips tutorial = Explode (",", $_server[' http_x_forwarded_for ');
if ($IP) {array_unshift ($ips, $ip); $ip = FALSE;}
for ($i = 0; $i < count ($ips); $i + +) {
if (!eregi ("^ (10│172.16│192.168).", $ips [$i])) {
$ip = $ips [$i];
Break
}
}
}
Return ($ip $ip: $_server[' remote_addr ');
}
Echo Getip_out ();
PHP Gets the IP algorithm, using the? Number expressions to handle
Copy CodeThe code is as follows:
$user _ip = ($_server["Http_via"])? $_server["Http_x_forwarded_for"]: $_server["REMOTE_ADDR"];
$user _ip = ($user _ip)? $user _ip: $_server["REMOTE_ADDR"];
A function to get the client IP address under PHP
PHP gets the real IP of the client
http://www.bkjia.com/PHPjc/321757.html www.bkjia.com true http://www.bkjia.com/PHPjc/321757.html techarticle after a complex judgment and a sort of obtaining the IP address function copy the code code as follows: function GetIP () {if (getenv (' Http_client_ip ')} {$ip = getenv (' http_client_ip ');} el Seif (getenv ( ...