PHP Get visitor IP Address summary, PHP get visitor IP
Method 1:
$ip = $_server["REMOTE_ADDR"];echo $ip;
Method 2:
Copy the Code code as follows:
$user _ip = ($_server["Http_via"])? $_server["Http_x_forwarded_for"]: $_server["REMOTE_ADDR"];
$user _ip = ($user _ip)? $user _ip: $_server["REMOTE_ADDR"];
echo $user _ip;
Method 3:
function Getrealip () { $ip =false; if (!empty ($_server["Http_client_ip")) { $ip = $_server["Http_client_ip"]; } if (!empty ($_server[' http_x_forwarded_for ')) { $ips = 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 Getrealip ();
Method 4:
if ($HTTP _server_vars["Http_x_forwarded_for"]) { $ip = $HTTP _server_vars["http_x_forwarded_for"];} ElseIf ($HTTP _server_vars["Http_client_ip") { $ip = $HTTP _server_vars["Http_client_ip"];} ElseIf ($HTTP _server_vars["Remote_addr") { $ip = $HTTP _server_vars["REMOTE_ADDR"];} ElseIf (getenv ("Http_x_forwarded_for")) { $ip = getenv ("Http_x_forwarded_for");} ElseIf (getenv ("Http_client_ip")) { $ip = getenv ("Http_client_ip");} ElseIf (getenv ("REMOTE_ADDR")) { $ip = getenv ("REMOTE_ADDR");} else{ $ip = "Unknown";} Echo $ip;
Method 5:
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;
Method 6:
Print "Your IP address is:", if (!empty ($_server["Http_client_ip")) {$cip = $_server["Http_client_ip"];} ElseIf (!empty ($_server["Http_x_forwarded_for")) {$cip = $_server["Http_x_forwarded_for"];} ElseIf (!empty ($_server["REMOTE_ADDR")) {$cip = $_server["REMOTE_ADDR"];} else{$cip = "Cannot get!" ";} Print $cip;
The above mentioned is the whole content of this article, I hope that we can learn PHP to help.
http://www.bkjia.com/PHPjc/989570.html www.bkjia.com true http://www.bkjia.com/PHPjc/989570.html techarticle php Get Visitor IP Address summary, PHP get visitor IP//Method 1: $ip = $_server["REMOTE_ADDR"];echo $ip;//Method 2: Copy code code as follows: $user _ip = ($_server["HTTP _via " ...