为什么geoip不适合我

问题描述 投票:-2回答:1

我正在尝试使用geoip来显示Ips及其国家。我试图显示此代码但没有出现?

$country = geoip_country_name_by_name($ip);
php centos
1个回答
1
投票

您必须先安装GeoIP功能。如果已安装,则可能的是,您提供给该功能的IP在数据库中不存在。

试试这段代码:

<?php

$country = geoip_country_name_by_name($ip);
if ($country) {
    echo 'This host is located in: ' . $country;
} else {
    echo 'Cannot find the IP in the database.'
}

© www.soinside.com 2019 - 2024. All rights reserved.