回答

收藏

根据ip查询地址信息

后台知识 后台知识 772 人阅读 | 0 人回复 | 2024-06-07

有个免费的接口:http://ip-api.com/php/ip

不过是有每日限额,最好请求后获取信息存入数据库以供下次使用
写个方法:

    function get_ip_info($data) {
                if(!$data['result']){
                        $url = "http://ip-api.com/php/".$data['inputip'];
                        $file_contents = file_get_contents($url);
                        $html = unserialize($file_contents);
                        $data['result'] = $html['country'].'-'.$html['regionName'].'-'.$html['city'];
                        \Phpcmf\Service::M()->db->table('dr_app_web_log')->where('id',$data['id'])->update(['result' => $data['result']]);
                }
               
        return $data['result'];
    }


$data是一条数据,查询无该地址信息就请求接口更改数据库信息。
分享到:
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

89 积分
17 主题
+ 关注