Skip to content

Commit

Permalink
Added Country class to query country information.
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Mar 24, 2021
1 parent 24365ff commit 57a80b7
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ Below is the description of the functions available in the **IpTools** class.
| **mixed** ipv6ToDecimal($ip) | Translate IPv6 address from hexadecimal address to decimal format. Return **null** on error. |
| **mixed** decimalToIpv6($number) | Translate IPv6 address from decimal number into hexadecimal address. Return **null** on error. |

### Country Class

Below is the description of the functions available in the **Country** class.

| Function Name | Description |
| -------------------------------------- | ------------------------------------------------------------ |
| Constructor | Expect a IP2Location Country Information CSV file. This database is free for download at https://www.ip2location.com/free/country-information |
| **array** getCountryInfo($countryCode) | Provide a ISO 3166 country code to get the country information in array. Will return a full list of countries information if country code not provided. |

## DEPENDENCIES

Expand Down
250 changes: 250 additions & 0 deletions data/IP2LOCATION-COUNTRY-INFORMATION-BASIC.CSV
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
"country_code","capital","total_area"
"AD","Andorra la Vella","468"
"AE","Abu Dhabi","83600"
"AF","Kabul","652230"
"AG","Saint John's","442"
"AI","The Valley","91"
"AL","Tirana","28748"
"AM","Yerevan","29743"
"AO","Luanda","1246700"
"AQ","-","14000000"
"AR","Buenos Aires","2780400"
"AS","Pago Pago","199"
"AT","Vienna","83871"
"AU","Canberra","7741220"
"AW","Oranjestad","180"
"AX","Mariehamn","1552"
"AZ","Baku","86600"
"BA","Sarajevo","51197"
"BB","Bridgetown","430"
"BD","Dhaka","143998"
"BE","Brussels","30528"
"BF","Ouagadougou","274200"
"BG","Sofia","110879"
"BH","Manama","760"
"BI","Bujumbura","27830"
"BJ","Porto-Novo","112622"
"BL","Gustavia","21"
"BM","Hamilton","54"
"BN","Bandar Seri Begawan","5765"
"BO","Sucre","1098581"
"BQ","Kralendijk","328"
"BR","Brasileia","8514877"
"BS","Nassau","13880"
"BT","Thimphu","38394"
"BV","-","49"
"BW","Gaborone","581730"
"BY","Minsk","207600"
"BZ","Belmopan","22966"
"CA","Ottawa","9984670"
"CC","West Island","14"
"CD","Kinshasa","2344858"
"CF","Bangui","622984"
"CG","Brazzaville","342000"
"CH","Bern","41277"
"CI","Yamoussoukro","322463"
"CK","Avarua","236"
"CL","Santiago","756102"
"CM","Yaounde","475440"
"CN","Beijing","9596961"
"CO","Bogota","1138910"
"CR","San Jose","51100"
"CU","Havana","110860"
"CV","Praia","4033"
"CW","Willemstad","444"
"CX","Flying Fish Cove","135"
"CY","Nicosia","9251"
"CZ","Prague","78867"
"DE","Berlin","357022"
"DJ","Djibouti","23200"
"DK","Copenhagen","43094"
"DM","Roseau","751"
"DO","Santo Domingo","48670"
"DZ","Algiers","2381741"
"EC","Quito","283561"
"EE","Tallinn","45228"
"EG","Cairo","1001450"
"EH","Laayoune / El Aaiun","266000"
"ER","Asmara","117600"
"ES","Madrid","505370"
"ET","Addis Ababa","1104300"
"FI","Helsinki","338145"
"FJ","Suva","18274"
"FK","Stanley","12173"
"FM","Palikir","702"
"FO","Torshavn","1393"
"FR","Paris","643801"
"GA","Libreville","267667"
"GB","London","243610"
"GD","Saint George's","344"
"GE","Tbilisi","69700"
"GF","Cayenne","86504"
"GG","Saint Peter Port","78"
"GH","Accra","238533"
"GI","Gibraltar","6"
"GL","Nuuk","2166086"
"GM","Banjul","11295"
"GN","Conakry","245857"
"GP","Basse-terre","1630"
"GQ","Malabo","28051"
"GR","Athens","131957"
"GS","Grytviken","3903"
"GT","Guatemala City","108889"
"GU","Hagatna","544"
"GW","Bissau","36125"
"GY","Georgetown","214969"
"HK","-","1104"
"HM","-","412"
"HN","Tegucigalpa","112090"
"HR","Zagreb","56594"
"HT","Port-au-prince","27750"
"HU","Budapest","93028"
"ID","Jakarta","1904569"
"IE","Dublin","70273"
"IL","Jerusalem","20770"
"IM","Douglas","572"
"IN","New Delhi","3287263"
"IO","Diego Garcia","54400"
"IQ","Baghdad","438317"
"IR","Tehran","1648195"
"IS","Reykjavik","103000"
"IT","Roma","301340"
"JE","Saint Helier","116"
"JM","Kingston","10991"
"JO","Amman","89342"
"JP","Tokyo","377915"
"KE","Nairobi","580367"
"KG","Bishkek","199951"
"KH","Phnom Penh","181035"
"KI","Tarawa","811"
"KM","Moroni","2235"
"KN","Basseterre","261"
"KP","Pyongyang","120538"
"KR","Seoul","99720"
"KW","Kuwait","17818"
"KY","George Town","264"
"KZ","Astana","2724900"
"LA","Vientiane","236800"
"LB","Beirut","10400"
"LC","Castries","616"
"LI","Vaduz","160"
"LK","Sri Jayewardenepura Kotte","65610"
"LR","Monrovia","111369"
"LS","Maseru","30355"
"LT","Vilnius","65300"
"LU","Luxembourg","2586"
"LV","Riga","64589"
"LY","Tripoli","1759540"
"MA","Rabat","446550"
"MC","Monaco","2"
"MD","Chisinau","33851"
"ME","Podgorica","13812"
"MF","Marigot","54"
"MG","Antananarivo","587041"
"MH","Majuro","181"
"MK","Skopje","25713"
"ML","Bamako","1240192"
"MM","Pyinmana","676578"
"MN","Ulaanbaatar","1564116"
"MO","-","31.3"
"MP","Saipan","464"
"MQ","Fort-de-france","1128"
"MR","Nouakchott","1030700"
"MS","Plymouth","102"
"MT","Valletta","316"
"MU","Port Louis","2040"
"MV","Male","298"
"MW","Lilongwe","118484"
"MX","Mexico City","1964375"
"MY","Kuala Lumpur","329847"
"MZ","Maputo","799380"
"NA","Windhoek","824292"
"NC","Noumea","18575"
"NE","Niamey","1186408"
"NF","Kingston","36"
"NG","Abuja","923768"
"NI","Managua","130370"
"NL","Amsterdam","41543"
"NO","Oslo","323802"
"NP","Kathmandu","147181"
"NR","Yaren","21"
"NU","Alofi","260"
"NZ","Wellington","267710"
"OM","Muscat","309500"
"PA","Panama","75420"
"PE","Lima","1285216"
"PF","Papeete","4167"
"PG","Port Moresby","462840"
"PH","Manila","300000"
"PK","Islamabad","796095"
"PL","Warsaw","312685"
"PM","Saint-pierre","242"
"PN","Adamstown","47"
"PR","San Juan","13790"
"PS","-","5860"
"PT","Lisbon","92090"
"PW","Melekeok - Palau State Capital","459"
"PY","Asuncion","406752"
"QA","Doha","11586"
"RE","Saint-denis","2512"
"RO","Bucharest","238391"
"RS","Belgrade","77474"
"RU","Moscow","17098242"
"RW","Kigali","26338"
"SA","Riyadh","2149690"
"SB","Honiara","28896"
"SC","Victoria","455"
"SD","Khartoum","1861484"
"SE","Stockholm","450295"
"SG","Singapore","697"
"SH","Jamestown","122"
"SI","Ljubljana","20273"
"SJ","Longyearbyen","62045"
"SK","Bratislava","49035"
"SL","Freetown","71740"
"SM","San Marino","61"
"SN","Dakar","196722"
"SO","Mogadishu","637657"
"SR","Paramaribo","163820"
"SS","Juba","644329"
"ST","Sao Tome","964"
"SV","San Salvador","21041"
"SX","Philipsburg","34"
"SY","Damascus","185180"
"SZ","Mbabane","17364"
"TC","Cockburn Town","948"
"TD","N'djamena","1284000"
"TF","Port-aux-francais","439781"
"TG","Lome","56785"
"TH","Bangkok","513120"
"TJ","Dushanbe","143100"
"TK","-","12"
"TL","Dili","14874"
"TM","Ashgabat","488100"
"TN","Tunis","163610"
"TO","Nuku'alofa","747"
"TR","Ankara","783562"
"TT","Port of Spain","5128"
"TV","Funafuti","26"
"TW","Taipei","35980"
"TZ","Dodoma","947300"
"UA","Kiev","603550"
"UG","Kampala","241038"
"UM","-","34.2"
"US","Washington, D.C.","9826675"
"UY","Montevideo","176215"
"UZ","Tashkent","447400"
"VA","Vatican City","0.44"
"VC","Kingstown","389"
"VE","Caracas","912050"
"VG","Road Town","151"
"VI","Charlotte Amalie","1910"
"VN","Ha Noi","331210"
"VU","Port-vila","12189"
"WF","Mata'utu","142"
"WS","Apia","2831"
"YE","Sanaa","527968"
"YT","Mamoudzou","374"
"ZA","Cape Town","1219090"
"ZM","Lusaka","752618"
"ZW","Harare","390757"
13 changes: 10 additions & 3 deletions examples/example.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

require 'vendor/autoload.php';

/*
Cache whole database into system memory and share among other scripts & websites
WARNING: Please make sure your system have sufficient RAM to enable this feature
Expand Down Expand Up @@ -60,8 +61,7 @@
echo 'Credit Remaining: ' . $ws->getCredit() . "\n";
echo '</pre>';


$ipTools = new \IP2Location\IpTools;
$ipTools = new \IP2Location\IpTools();

// Validate IPv4 address
var_dump($ipTools->isIpv4('8.8.8.8'));
Expand Down Expand Up @@ -89,4 +89,11 @@
echo '<br>';

// Convert decimal into IPv6 address
echo $ipTools->decimalToIpv6('42541956123769884636017138956568135816');
echo $ipTools->decimalToIpv6('42541956123769884636017138956568135816');

// List country information for US
$country = new \IP2Location\Country('./data/IP2LOCATION-COUNTRY-INFORMATION-BASIC.CSV');

echo '<pre>';
print_r($country->getCountryInfo('US'));
echo '</pre>';
Loading

0 comments on commit 57a80b7

Please sign in to comment.