Thinkphp methods for obtaining client IP and IP address queries

Source: Internet
Author: User
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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.