How does thinkphp obtain the client IP address and thinkphp obtain the ip address. How does thinkphp obtain the client IP address? the get_client_ip method is built in the ipthinkphp framework to obtain the client IP address. example: $ ipget_client_ip (); in addition to how thinkphp obtains the client ip address, thinkphp obtains the IP address
The get_client_ip method is built in the thinkphp framework to obtain the IP address of the client. example:
$ Ip = get_client_ip ();
In addition to the built-in get_client_ip function of thinkphp, you can also use the following function to obtain the client IP address.
$ Type indicates that the return type 0 returns the IP address, and 1 returns the IPV4 address number.
The sharing code is as follows:
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 = ip2long ($ ip); $ ip = $ long? Array ($ ip, $ long): array ('0. 0.0.0 ', 0); return $ ip [$ type];
I hope this article will help you to learn more about php programming.
The get_client_ip method is built in the thinkphp framework to obtain the client ip address. example: $ ip = get_client_ip (); except...