PHP queries the ip address location (province, city ). This article introduces how to use relevant api interfaces to obtain a php instance in the city based on the client IP address. let's take a look at it. Today, we will share a PHP client IP address. This article introduces how to use relevant api interfaces to obtain a php instance in the city or region based on the client IP address. let's take a look at it.
Today, I am sharing a PHP app that obtains the location of the app based on the client IP address. I have been using this app for a long time and I feel that this interface is still stable. Although there are many similar items on the Internet, I think this is quite good. The core code can be implemented in only three lines. Although the function is not very powerful, we usually use it. The following code is used:
The code is as follows: |
|
Obtain the region through IP address : Returned data
: Query successful
If you like it, you can try it and get a few lines of code. I think it is quite practical !!
This article from the generation of Ruibo customer original address: http://www.daixiaorui.com/read/3.html // Obtain the IP address // $ Ip = $ _ SERVER ['remote _ ADDR ']; // automatically obtains the IP address of the client. // Region corresponding to the ip address If (! Empty ($ _ POST ['IP']) { $ Ip = $ _ POST ['IP']; // Interface address, which returns an xml result set, 1; $ Str = file_get_contents ("http://www.yodao.com/smartresult-xml/search.s? Type = ip & q = ". $ ip ); // Here we need to get the address information. There are many xml extraction methods, and I use regular expressions. Preg_match_all ("/ (.*?) /", $ Str, $ addr1 ); // Final result, 2; $ Addr = $ ip. "=>". $ addr1 [1] [0]; Echo $ addr; } ?> |
: Returned data
: Query successful
If you like it, you can try it and get a few lines of code. I think it is quite practical !!
Bytes. Today, I will share a PHP file to obtain the IP address of the client...