The example in this article describes how thinkphp obtains client IP and IP address queries. Share to everyone for your reference, specific as follows:
The public function of the system that obtains the client IP address in TP is the function get_client_ip (). The return value is the IP address.
The class file of the country and region where the IP address is queried 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 = ');
Query client IP address when omitted. Returns an array. The return value is null if it is not found; the value of the array is:
$location [' IP '];
$location [' Country '];
$location [' area '];
The specific application process for querying client IP and its corresponding area is:
Import (' ORG.Net.IpLocation ');
$ip =new iplocation ()//Create a new IP query object
$location = $ip->getlocation (), or the query client IP when omitted. $location can be output directly using the key name as above.
If you want to query for a specific IP or domain name, the procedure is:
Import (' ORG.Net.IpLocation ');
$ip =new iplocation ()//Create a new IP query object
$ipname = ' 202.38.68.68′;//or can use domain names, such as $ipname= ' www.64hi.com ';
$location = $ip->getlocation ($ipname);//$location can be output directly using the key name as above.
If you only query the client IP address, you can use the system function 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.
More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."
I hope this article will help you with the PHP program design based on thinkphp framework.