328 lines
9.7 KiB
PHP
328 lines
9.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* (c) 2025 Sakuragasaki46
|
||
|
|
*
|
||
|
|
* This is an interface to the IP2Location Lite country IP database, CC BY-SA licensed
|
||
|
|
* and accessible free of charge at <https://lite.ip2location.com> (registration required).
|
||
|
|
* IP2Location Lite® is a registered trademark of Hexasoft Development Sdn Bhd.
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace Yusurko\UserAgent;
|
||
|
|
|
||
|
|
use Yusurko\UserAgent\RegionBlock;
|
||
|
|
|
||
|
|
class Country {
|
||
|
|
const NAMES = [
|
||
|
|
'@' => 'Headspace',
|
||
|
|
'+' => 'Inner Space',
|
||
|
|
'-' => 'Outer Space',
|
||
|
|
'AC' => 'Ascension (UK)',
|
||
|
|
'AD' => 'Andorra',
|
||
|
|
'AE' => 'United Arab Emirates',
|
||
|
|
'AF' => 'Afghanistan',
|
||
|
|
'AG' => 'Antigua & Barbuda',
|
||
|
|
'AI' => 'Anguilla (UK)',
|
||
|
|
'AL' => 'Albania',
|
||
|
|
'AM' => 'Armenia',
|
||
|
|
'AO' => 'Angola',
|
||
|
|
'AQ' => 'Antarctica',
|
||
|
|
'AR' => 'Argentina',
|
||
|
|
'AS' => 'American Samoa',
|
||
|
|
'AT' => 'Austria',
|
||
|
|
'AU' => 'Australia',
|
||
|
|
'AW' => 'Aruba (Netherlands)',
|
||
|
|
'AX' => 'Åland (Finland)',
|
||
|
|
'AZ' => 'Azerbaijan',
|
||
|
|
'BA' => 'Bosnia & Herzegovina',
|
||
|
|
'BB' => 'Barbados',
|
||
|
|
'BD' => 'Bangladesh',
|
||
|
|
'BE' => 'Belgium',
|
||
|
|
'BF' => 'Burkina Faso',
|
||
|
|
'BG' => 'Bulgaria',
|
||
|
|
'BH' => 'Bahrain',
|
||
|
|
'BI' => 'Burundi',
|
||
|
|
'BJ' => 'Benin',
|
||
|
|
'BL' => 'Saint Barthélemy (France)',
|
||
|
|
'BM' => 'Bermuda (UK)',
|
||
|
|
'BN' => 'Brunei',
|
||
|
|
'BO' => 'Bolivia',
|
||
|
|
'BQ' => 'Bonaire (Netherlands)',
|
||
|
|
'BR' => 'Brazil',
|
||
|
|
'BS' => 'Bahamas',
|
||
|
|
'BT' => 'Bhutan',
|
||
|
|
'BV' => 'Bouvet Island (Norway)',
|
||
|
|
'BW' => 'Botswana',
|
||
|
|
'BY' => 'Belarus',
|
||
|
|
'BZ' => 'Belize',
|
||
|
|
'CA' => 'Canada',
|
||
|
|
'CC' => 'Cocos (Keeling) Islands (Australia)',
|
||
|
|
'CD' => 'Democratic Republic of the Congo',
|
||
|
|
'CF' => 'Central African Republic',
|
||
|
|
'CG' => 'Republic of the Congo',
|
||
|
|
'CH' => 'Switzerland',
|
||
|
|
'CI' => 'Côte d\'Ivoire',
|
||
|
|
'CK' => 'Cook Islands (UK)',
|
||
|
|
'CL' => 'Chile',
|
||
|
|
'CM' => 'Cameroon',
|
||
|
|
'CN' => 'People\'s Republic of China',
|
||
|
|
'CO' => 'Colombia',
|
||
|
|
'CP' => 'France',
|
||
|
|
'CQ' => 'Sark (UK)',
|
||
|
|
'CR' => 'Costa Rica',
|
||
|
|
'CU' => 'Cuba',
|
||
|
|
'CV' => 'Cape Verde',
|
||
|
|
'CW' => 'Curaçao (Netherlands)',
|
||
|
|
'CX' => 'Christmas Island (Australia)',
|
||
|
|
'CY' => 'Cyprus',
|
||
|
|
'CZ' => 'Czechia',
|
||
|
|
'DE' => 'Germany',
|
||
|
|
'DG' => 'Chagos (Mauritius)',
|
||
|
|
'DJ' => 'Djibouti',
|
||
|
|
'DK' => 'Denmark',
|
||
|
|
'DM' => 'Dominica',
|
||
|
|
'DO' => 'Dominican Republic',
|
||
|
|
'DZ' => 'Algeria',
|
||
|
|
'EA' => 'Spain',
|
||
|
|
'EC' => 'Ecuador',
|
||
|
|
'EE' => 'Estonia',
|
||
|
|
'EG' => 'Egypt',
|
||
|
|
'EH' => 'Western Sahara',
|
||
|
|
'ER' => 'Eritrea',
|
||
|
|
'ES' => 'Spain',
|
||
|
|
'ET' => 'Ethiopia',
|
||
|
|
'EU' => 'European Union',
|
||
|
|
'EZ' => 'Eurozone',
|
||
|
|
'FI' => 'Finland',
|
||
|
|
'FJ' => 'Fiji',
|
||
|
|
'FK' => 'Falkland Islands (UK)',
|
||
|
|
'FM' => 'Federated States of Micronesia',
|
||
|
|
'FO' => 'Faroe Islands (Denmark)',
|
||
|
|
'FR' => 'France',
|
||
|
|
'FX' => 'France',
|
||
|
|
'GA' => 'Gabon',
|
||
|
|
'GB' => 'United Kingdom (wrong)',
|
||
|
|
'GD' => 'Grenada',
|
||
|
|
'GE' => 'Georgia',
|
||
|
|
'GF' => 'French Guyane',
|
||
|
|
'GG' => 'Guernsey (UK)',
|
||
|
|
'GH' => 'Ghana',
|
||
|
|
'GI' => 'Gibraltar (UK)',
|
||
|
|
'GL' => 'Greenland (Denmark)',
|
||
|
|
'GM' => 'Gambia',
|
||
|
|
'GN' => 'Guinea',
|
||
|
|
'GP' => 'Guadeloupe (France)',
|
||
|
|
'GQ' => 'Equatorial Guinea',
|
||
|
|
'GR' => 'Greece',
|
||
|
|
'GS' => 'South Georgia & South Sandwich Islands (UK)',
|
||
|
|
'GT' => 'Guatemala',
|
||
|
|
'GU' => 'Guam (USA)',
|
||
|
|
'GW' => 'Guinea-Bissau',
|
||
|
|
'GY' => 'Guyana',
|
||
|
|
'HK' => 'Hong Kong (PRC)',
|
||
|
|
'HM' => 'Heard & McDonald Islands (Australia)',
|
||
|
|
'HN' => 'Honduras',
|
||
|
|
'HR' => 'Croatia',
|
||
|
|
'HT' => 'Haïti',
|
||
|
|
'HU' => 'Hungary',
|
||
|
|
'IC' => 'Canary Islands (Spain)',
|
||
|
|
'ID' => 'Indonesia',
|
||
|
|
'IE' => 'Ireland',
|
||
|
|
'IL' => 'Israel',
|
||
|
|
'IM' => 'Isle of Man (UK)',
|
||
|
|
'IN' => 'India (Bharat)',
|
||
|
|
'IO' => 'Chagos (Mauritius)',
|
||
|
|
'IQ' => 'Iraq',
|
||
|
|
'IR' => 'Iran',
|
||
|
|
'IS' => 'Iceland',
|
||
|
|
'IT' => 'Italy',
|
||
|
|
'JE' => 'Jersey (UK)',
|
||
|
|
'JM' => 'Jamaica',
|
||
|
|
'JO' => 'Jordan',
|
||
|
|
'JP' => 'Japan',
|
||
|
|
'KE' => 'Kenya',
|
||
|
|
'KG' => 'Kyrgyzstan',
|
||
|
|
'KH' => 'Cambodia',
|
||
|
|
'KI' => 'Kiribati',
|
||
|
|
'KM' => 'Comoros',
|
||
|
|
'KN' => 'Saint Kitts & Nevis',
|
||
|
|
'KP' => 'Democratic People\'s Republic of Korea',
|
||
|
|
'KR' => 'Republic of Korea',
|
||
|
|
'KW' => 'Kuwait',
|
||
|
|
'KY' => 'Cayman Islands (UK)',
|
||
|
|
'KZ' => 'Kazakhstan',
|
||
|
|
'LA' => 'Laos',
|
||
|
|
'LB' => 'Lebanon',
|
||
|
|
'LC' => 'Saint Lucia',
|
||
|
|
'LI' => 'Liechtenstein',
|
||
|
|
'LK' => 'Sri Lanka',
|
||
|
|
'LR' => 'Liberia',
|
||
|
|
'LS' => 'Lesotho',
|
||
|
|
'LT' => 'Lithuania',
|
||
|
|
'LU' => 'Luxembourg',
|
||
|
|
'LV' => 'Latvia',
|
||
|
|
'LY' => 'Libya',
|
||
|
|
'MA' => 'Morocco',
|
||
|
|
'MC' => 'Monaco',
|
||
|
|
'MD' => 'Moldova',
|
||
|
|
'ME' => 'Montenegro',
|
||
|
|
'MF' => 'Saint Martin (France)',
|
||
|
|
'MG' => 'Madagascar',
|
||
|
|
'MH' => 'Marshall Islands',
|
||
|
|
'MK' => 'North Macedonia',
|
||
|
|
'ML' => 'Mali',
|
||
|
|
'MM' => 'Myanmar',
|
||
|
|
'MN' => 'Mongolia',
|
||
|
|
'MO' => 'Macao (PRC)',
|
||
|
|
'MP' => 'Northern Mariana Islands (USA)',
|
||
|
|
'MQ' => 'Martinique (France)',
|
||
|
|
'MR' => 'Mauritania',
|
||
|
|
'MS' => 'Montserrat (United Kingdom)',
|
||
|
|
'MT' => 'Malta',
|
||
|
|
'MU' => 'Mauritius',
|
||
|
|
'MV' => 'Maldives',
|
||
|
|
'MW' => 'Malawi',
|
||
|
|
'MX' => 'Mexico',
|
||
|
|
'MY' => 'Malaysia',
|
||
|
|
'MZ' => 'Mozambique',
|
||
|
|
'NA' => 'Namibia',
|
||
|
|
'NC' => 'New Caledonia (France)',
|
||
|
|
'NE' => 'Niger',
|
||
|
|
'NF' => 'Norfolk Island (Australia)',
|
||
|
|
'NG' => 'Nigeria',
|
||
|
|
'NI' => 'Nicaragua',
|
||
|
|
'NL' => 'Netherlands',
|
||
|
|
'NO' => 'Norway',
|
||
|
|
'NP' => 'Nepal',
|
||
|
|
'NR' => 'Nauru',
|
||
|
|
'NU' => 'Niue (NZ)',
|
||
|
|
'NZ' => 'New Zealand',
|
||
|
|
'OM' => 'Oman',
|
||
|
|
'PA' => 'Panama',
|
||
|
|
'PE' => 'Peru',
|
||
|
|
'PF' => 'French Polynesia',
|
||
|
|
'PG' => 'Papua New Guinea',
|
||
|
|
'PH' => 'Philippines',
|
||
|
|
'PK' => 'Pakistan',
|
||
|
|
'PL' => 'Poland',
|
||
|
|
'PM' => 'Saint Pierre & Miquelon (France)',
|
||
|
|
'PN' => 'Pitcairn (UK)',
|
||
|
|
'PR' => 'Puerto Rico (USA)',
|
||
|
|
'PS' => 'Palestinian Authority',
|
||
|
|
'PT' => 'Portugal',
|
||
|
|
'PW' => 'Palau',
|
||
|
|
'PY' => 'Paraguay',
|
||
|
|
'QA' => 'Qatar',
|
||
|
|
'QM' => 'Mars',
|
||
|
|
'RE' => 'Réunion (France)',
|
||
|
|
'RO' => 'Romania',
|
||
|
|
'RS' => 'Serbia',
|
||
|
|
'RU' => 'Russian Federation',
|
||
|
|
'RW' => 'Rwanda',
|
||
|
|
'SA' => 'Saudi Arabia',
|
||
|
|
'SB' => 'Solomon Islands',
|
||
|
|
'SC' => 'Seychelles',
|
||
|
|
'SD' => 'Sudan',
|
||
|
|
'SE' => 'Sweden',
|
||
|
|
'SG' => 'Singapore',
|
||
|
|
'SH' => 'Saint Helena (UK)',
|
||
|
|
'SI' => 'Slovenia',
|
||
|
|
'SJ' => 'Svalbard & Jan Mayen (Norway)',
|
||
|
|
'SK' => 'Slovakia',
|
||
|
|
'SL' => 'Sierra Leone',
|
||
|
|
'SM' => 'San Marino',
|
||
|
|
'SN' => 'Senegal',
|
||
|
|
'SO' => 'Somalia',
|
||
|
|
'SR' => 'Suriname',
|
||
|
|
'SS' => 'South Sudan',
|
||
|
|
'ST' => 'Sao Tome & Principe',
|
||
|
|
'SU' => 'Soviet Union',
|
||
|
|
'SV' => 'El Salvador',
|
||
|
|
'SX' => 'Sint Maarten (Netherlands)',
|
||
|
|
'SY' => 'Syria',
|
||
|
|
'SZ' => 'eSwatini',
|
||
|
|
'TA' => 'Tristan da Cunha (UK)',
|
||
|
|
'TC' => 'Turks and Caicos Islands (UK)',
|
||
|
|
'TD' => 'Chad',
|
||
|
|
'TF' => 'French Southern Territories',
|
||
|
|
'TG' => 'Togo',
|
||
|
|
'TH' => 'Thailand',
|
||
|
|
'TK' => 'Tokelau',
|
||
|
|
'TL' => 'Timor-Leste',
|
||
|
|
'TM' => 'Turkmenistan',
|
||
|
|
'TN' => 'Tunisia',
|
||
|
|
'TO' => 'Tonga',
|
||
|
|
'TR' => 'Türkiye',
|
||
|
|
'TT' => 'Trinidad & Tobago',
|
||
|
|
'TV' => 'Tuvalu',
|
||
|
|
'TW' => 'Republic of China (Taiwan)',
|
||
|
|
'TZ' => 'Tanzania',
|
||
|
|
'UA' => 'Ukraine',
|
||
|
|
'UG' => 'Uganda',
|
||
|
|
'UK' => 'United Kingdom',
|
||
|
|
'UM' => 'USA Minor Outlying Islands',
|
||
|
|
'UN' => 'United Nations',
|
||
|
|
'US' => 'United States of America',
|
||
|
|
'UY' => 'Uruguay',
|
||
|
|
'UZ' => 'Uzbekistan',
|
||
|
|
'VA' => 'Vatican City',
|
||
|
|
'VC' => 'Saint Vincent & Grenadines',
|
||
|
|
'VE' => 'Venezuela',
|
||
|
|
'VG' => 'British Virgin Islands',
|
||
|
|
'VI' => 'US Virgin Islands',
|
||
|
|
'VN' => 'Vietnam',
|
||
|
|
'VU' => 'Vanuatu',
|
||
|
|
'WF' => 'Wallis & Futuna (France)',
|
||
|
|
'WS' => 'Samoa',
|
||
|
|
'XK' => 'Kosovo',
|
||
|
|
'YE' => 'Yemen',
|
||
|
|
'YT' => 'Mayotte (France)',
|
||
|
|
'ZA' => 'South Africa',
|
||
|
|
'ZM' => 'Zambia',
|
||
|
|
'ZW' => 'Zimbabwe'
|
||
|
|
];
|
||
|
|
|
||
|
|
const EUROPE = array (
|
||
|
|
'AD', 'AL', 'AT', 'AX', 'BA', 'BE', 'BG', 'CH',
|
||
|
|
'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FO',
|
||
|
|
'FR', 'GE', 'GF', 'GG', 'GI', 'GL', 'GR',
|
||
|
|
'HR', 'HU', 'IE', 'IM', 'IS', 'IT', 'LI', 'LT',
|
||
|
|
'LU', 'LV', 'MC', 'MD', 'ME', 'MK', 'MQ', 'MT',
|
||
|
|
'NL', 'NO', 'PL', 'PT', 'RO', 'SE', 'SI', 'SJ',
|
||
|
|
'SK', 'SM', 'VA', '@', '+'
|
||
|
|
);
|
||
|
|
|
||
|
|
protected $cc;
|
||
|
|
|
||
|
|
public function __construct ($cc) {
|
||
|
|
$this->cc = $cc;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getCode () {
|
||
|
|
return $this->cc;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getName() {
|
||
|
|
return self::NAMES[$this->cc] ?? $this->cc;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isEurope() {
|
||
|
|
return in_array($this->cc, self::EUROPE, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isUS() {
|
||
|
|
return in_array($this->cc, [ 'US', 'UM', 'QM' ], true);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isBlocked() {
|
||
|
|
return (new RegionBlock($this->cc))->isBlocked();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isInnerSpace() {
|
||
|
|
return in_array($this->cc, [ '@', '+' ], true);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function outerSpace() {
|
||
|
|
return new self("-");
|
||
|
|
}
|
||
|
|
}
|