检查 GeoLite2 是不是有 IP 地址

Posted

技术标签:

【中文标题】检查 GeoLite2 是不是有 IP 地址【英文标题】:Checking GeoLite2 have IP Adress检查 GeoLite2 是否有 IP 地址 【发布时间】:2020-04-20 14:19:41 【问题描述】:

我使用this repository。

但是,我不知道如何检查该数据是否存在。

帮帮我。

所有代码错误。

Reader::connect()->city($_SERVER["REMOTE_ADDR"]);
Reader::connect()->city($_SERVER["REMOTE_ADDR"])->mostSpecificSubdivision->name;
Reader::connect()->city($request->ip());
Reader::connect()->city($request->ip())->mostSpecificSubdivision->name;

首先,在城市功能的时候发生了错误。

【问题讨论】:

$variable_name = $reader->city($ip)->jsonSerialize();检查$variable_name @A.ANoman "地址 xxx.xxx.xxx.xxx 不在数据库中。" 那么你从哪里得到ip_address?? 这边:$request->ip() 这也会报错。 Reader::connect()->city($_SERVER["REMOTE_ADDR"]); 【参考方案1】:

检查您的 ip 是否存在使用isset 如下所示

if(isset($request->ip()))
    //Your code here

【讨论】:

你明白吗?我可以得到IP地址。但是,当 IP 地址不在 GeoLite2 数据库中时,我想自己处理而不返回错误。 您在本教程中的详细回答

以上是关于检查 GeoLite2 是不是有 IP 地址的主要内容,如果未能解决你的问题,请参考以下文章