This article mainly introduces the thinkphp to obtain the client IP and IP address query method, combined with the case analysis of the thinkphp for the client IP address operation of the relevant functions and the use of skills, the need for friends can refer to the next
The example in this paper describes the method of obtaining client IP and IP address query thinkphp. Share to everyone for your reference, as follows:
The system common function that gets the client IP address in TP is: function Get_client_ip (). The return value is the IP address.
Query the IP address of the country and region of the class file is IpLocation.class.php, located in the Thinkphp\lib\org\net directory. The class name is Iplocation, and the method is
Public Function getlocation ($ip = ");
The address of the client IP is queried when omitted. The return is an array. Not found. The return value is empty; If you do, the array has the value:
$location [' IP ']; $location [' Country ']; $location [' Area '];
The specific application process for querying client IPs and their corresponding regions is:
Import (' ORG.Net.IpLocation '); $ip =new iplocation ();//Create a new IP query object $location= $ip->getlocation ();//omit to indicate query client ip.$ Location can be directly output using the key name as above.
If you want to query the region of a specific IP or domain name, the process is:
Import (' ORG.Net.IpLocation '); $ip =new iplocation ();//Create a new IP query object $ipname= ' 202.38.68.68′;//or you can use a domain name, such as $ipname= ' www.64hi.com '; $ location= $ip->getlocation ($ipname);//$location can be used for direct output, key name as above.
If you just query the client IP address, you can use system functions directly, such as:
$ip = $ip->get_client_ip ();//Many sites are $ip = Get_client_ip (); In fact, all are wrong, we should pay attention to.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!