In fact, there are many ways to use PHP to obtain the client IP address on the internet. I have collected some methods before, but here I mainly recommend the thinkphp framework, after all, I have been using the thinkphp framework and its method all the time.
/*** 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'];} // valid ip address verification $ long = sprintf ("% u", ip2long ($ ip); $ ip = $ long? Array ($ ip, $ long): array ('0. 0.0.0 ', 0); return $ ip [$ type];}
The above is the function that comes with the thinkphp framework to obtain the client IP address. the call method is as follows:
get_client_ip();