How does php obtain the client ip address and the specific implementation code of the province and city .. Thank you .. ------ Solution ------------------ how many IP address APIs are provided? Sina's IP address query interface: int.dpool.sina.com. cniplookupiplookup. php? Formatjs Sina another ip address query interface: How does cou php obtain the client ip address and the province and city
Find the specific implementation code .. Thank you ..
------ Solution --------------------
Provides several IP address APIs
Sina IP address query interface: http://int.dpool.sina.com.cn/iplookup/iplookup.php? Format = js
Sina another IP address query interface: http://counter.sina.com.cn/ip
Sina multi-region Test Method: http://int.dpool.sina.com.cn/iplookup/iplookup.php? Format = js & ip = 218.192.3.42
Sohu IP address query interface (default GBK): http://pv.sohu.com/cityjson
Sohu IP address query interface (can be set encoding): http://pv.sohu.com/cityjson? Ie = UTF-8
Sohu another IP address query interface: http://txt.go.sohu.com/ip/soip
------ Solution --------------------
1. you can build your own ip database, and the data can be extracted from data packets similar to innocence.
2. get the ip Code. copy one of the following code on the Internet:
Function getip ()
{
If (getenv ("HTTP_CLIENT_IP") & strcasecmp (getenv ("HTTP_CLIENT_IP"), "unknown "))
{
$ Ip = getenv ("HTTP_CLIENT_IP ");
} Else
If (getenv ("HTTP_X_FORWARDED_FOR") & strcasecmp (getenv ("HTTP_X_FORWARDED_FOR "),
"Unknown "))
{
$ Ip = getenv ("HTTP_X_FORWARDED_FOR ");
} Else
If (getenv ("REMOTE_ADDR") & strcasecmp (getenv ("REMOTE_ADDR"), "unknown "))
{
$ Ip = getenv ("REMOTE_ADDR ");
} Else
If (isset ($ _ SERVER ['remote _ ADDR ']) & $ _ SERVER ['remote _ ADDR '] & strcasecmp ($ _ SERVER ['remote _ ADDR'],
"Unknown "))
{
$ Ip = $ _ SERVER ['remote _ ADDR '];
} Else
{
$ Ip = "unknown ";
}
Return ($ ip );
}
3. you can pass the ip address to some interfaces available on the Internet to retrieve the returned data for resolution.
For example
Http://int.dpool.sina.com.cn/iplookup/iplookup.php? Format = js & ip = 219.136.252.33
Note that the visitor's ip address is automatically obtained if no ip address is transferred.