Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Created December 8, 2018 15:37
Show Gist options
  • Save pandanote-info/10c9e7086a65f7c8ad815ed480b90337 to your computer and use it in GitHub Desktop.
Save pandanote-info/10c9e7086a65f7c8ad815ed480b90337 to your computer and use it in GitHub Desktop.
アクセス元のIPアドレスから国名のISOコード(2字国名コード)を得るためのWordpress用の関数。
<?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