THinkPHP queries the Client IP address and IP address.
This example describes how THinkPHP can query the Client IP address and IP address. We will share this with you for your reference. The details are as follows:
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 this parameter is omitted, the IP address of the client is queried. Returns an array. If no value is found, the returned value is null. If yes, the value of the array is:
$location['ip'];$location['country'];$location['area'];
The specific application process for querying the Client IP address and the 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 as follows:
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:
$ Ip = $ ip-> get_client_ip (); // many websites use $ ip = get_client_ip (). In fact, they are all incorrect.