简体   繁体   English

PHP:如何根据IP地址获取位置信息

[英]Php : How to get localities based on ip address

I want to get localities based on IP address in Php. 我想根据Php中的IP地址获取位置。 I'm using geoplugin for based on IP, I got cities by using this 我正在使用基于IP的geoplugin,我通过使用此工具获得了城市

$ip_address = $_SERVER['REMOTE_ADDR'];
/*Get user ip address details with geoplugin.net*/
$geopluginURL='http://www.geoplugin.net /php.gp?ip='.$ip_address;
$addrDetailsArr =     unserialize(file_get_contents($geopluginURL)); 
/*Get City name by return array*/
$city = $addrDetailsArr['geoplugin_city']; 

/*Get Country name by return array*/

$country = $addrDetailsArr['geoplugin_countryName'];

Then, how to get locations of the city in selected field using this 然后,如何使用此方法在所选字段中获取城市的位置

Feel free to use this IP-Api . 随时使用此IP-Api It is free. 这是免费的。 Data returned will give you the local and other details. 返回的数据将为您提供本地和其他详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM