PHP Get IP Address code summary, PHP get IP summary
Code One:
function GetIP () { static $ip = '; $ip = $_server[' remote_addr '); if (Isset ($_server[' http_cdn_src_ip ')) { $ip = $_server[' http_cdn_src_ip ']; } elseif (Isset ($_server[' http_ Client_ip ']) && preg_match ('/^ ([0-9]{1,3}\.) {3} [0-9] {1,3}$/', $_server[' http_client_ip ')) { $ip = $_server[' http_client_ip ']; } elseif (Isset ($_server[' http_x_ Forwarded_for ']) and Preg_match_all (' #\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} #s ', $_server[' Http_x_forwarded_for '], $ Matches) { foreach ($matches [0] as $XIP) { if (!preg_match (' #^ (10|172\.16|192\.168) \.# ', $xip)) { $ip = $ XIP; Break ; }}} return $IP;}
Code two:
<?phperror_reporting (E_error | e_warning | E_parse), 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 Three:
<?php$iipp = $_server["REMOTE_ADDR"];echo $iipp;? >
Method Four:
<?php$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 Five:
<?phpfunction get_real_ip () {$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\.1 6|192\.168) \ ", $ips [$i])) { $ip = $ips [$i]; break; } }}return ($ip? $ip: $_server[' remote_addr ');} Echo get_real_ip ();? >
Method Six:
<?phpif (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;? >
http://www.bkjia.com/PHPjc/1027052.html www.bkjia.com true http://www.bkjia.com/PHPjc/1027052.html techarticle PHP Get IP Address code summary, PHP get IP Summary Code one: function GetIP () {Static $ip = '; $ip = $_server[' remote_addr ']; if (isset ($_server[' HT Tp_cdn_src_ip ']) {$ip = $_ ...