The system public function for obtaining the Client IP address in TP is: function get_client_ip (). The returned value is the IP address.
The class file for querying the country and region of the IP address is iplocation. Class. php, which is located in the thinkphp \ Lib \ org \ net directory. The class name is iplocation, and the method is public function getlocation ($ IP = "); // if it is omitted, query the IP address of the client. Returns an array. If no value is found, the returned value is null. If yes, the array value is $ location ['IP']; $ location ['country']; $ location ['region']; the specific application process for querying the Client IP address and its corresponding region is: Import ('org. net. iplocation '); $ IP = new iplocation (); // create an IP query object $ location = $ IP-> getlocation (); // if it is omitted, the Client IP address is queried. $ location can be output directly, with the key name as above. To query the region of a specific IP address or domain name, the process is: Import ('org. net. iplocation '); $ IP = new iplocation (); // create an IP query object $ ipname = '2017. 38.68.68 '; // or you can use a domain name, such as $ ipname = 'www .64hi.com'; $ location = $ IP-> getlocation ($ ipname ); // $ location can be output directly, with the key name as above. If you only need to query the Client IP address, you can directly use the system function, such as: $ IP = $ IP-> Get_client_ip (); // many websites use $ IP = Get_client_ip (); in fact, they are all incorrect.