谁能告诉我如何通过自动识别IP地址在下拉列表中选择状态?我没有尝试过任何东西,所以如果你有任何公式,请帮助我。
谢谢
您可能
想尝试 http://ipinfo.io/
.PHP:
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
echo $details->city; // -> "Mountain View"
或者在 JavaScript 中:
$.get("http://ipinfo.io", function(response) {
console.log(response.city);
}, "jsonp");