获取用户当前位置

2022-01-14 00:00:00 ip geolocation php

如何根据IP确定用户当前位置(我猜是这样).

How can I determine user's current location based on IP (I guess it works this way).

推荐答案

<?php
$user_ip = getenv('REMOTE_ADDR');
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
$country = $geo["geoplugin_countryName"];
$city = $geo["geoplugin_city"];
?>

相关文章