Created
December 8, 2018 15:37
-
-
Save pandanote-info/10c9e7086a65f7c8ad815ed480b90337 to your computer and use it in GitHub Desktop.
アクセス元のIPアドレスから国名のISOコード(2字国名コード)を得るためのWordpress用の関数。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once '/usr/share/php/GeoIP2-php/vendor/autoload.php'; | |
use GeoIp2\Database\Reader; | |
function get_country_isocode() { | |
global $country_isocode; | |
if (empty($country_isocode)) { | |
$reader = new Reader('/usr/share/GeoIP/GeoLite2-Country.mmdb'); | |
$record = $reader->country($_SERVER["REMOTE_ADDR"]); | |
$country_isocode = $record->country->isoCode; | |
} | |
return $country_isocode; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment