在PHP中按IP地址获取国家
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在PHP中按IP地址获取国家相关的知识,希望对你有一定的参考价值。
This simple function allows you to getect a country code and city of your site visitors, using the www.geoplugin.net service. You may use this data to add default values in registration form or use it for any other purposes, like blocking access to your site from special regions.
<?php function getLocationInfoByIp(){ $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = @$_SERVER['REMOTE_ADDR']; $ip = $client; $ip = $forward; }else{ $ip = $remote; } if($ip_data && $ip_data->geoplugin_countryName != null){ $result['country'] = $ip_data->geoplugin_countryCode; $result['city'] = $ip_data->geoplugin_city; } return $result; } ?>
以上是关于在PHP中按IP地址获取国家的主要内容,如果未能解决你的问题,请参考以下文章