/** * Get client IP address * @param integer $type return type 0 return IP address 1 return IPV4 address number * @return mixed */function get_client_ip ($type = 0) {
$type = $type? 1:0; static $ip = NULL; if ($ip!== NULL) return $ip [$type]; if (Isset ($_server[' http_x_forwarded_for ')) { $arr = explode (', ', $_server[' http_x_forwarded_for ')) ; $pos = array_search (' unknown ', $arr); if (false!== $pos) unset ($arr [$pos]); $ip = Trim ($arr [0]); } ElseIf (Isset ($_server[' http_client_ip ')) { $ip = $_server[' http_client_ip ']; } ElseIf (Isset ($_server[' remote_addr ')) { $ip = $_server[' remote_addr ']; } IP Address valid authentication $long = sprintf ("%u", Ip2long ($IP)); $ip = $long? Array ($ip, $long): Array (' 0.0.0.0 ', 0); return $ip [$type];}
The above is the thinkphp framework comes with a function to get the client IP address, calling the method
Get_client_ip ();