-
Notifications
You must be signed in to change notification settings - Fork 8
/
example.php
106 lines (89 loc) · 4.26 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
require_once 'class.IP2LocationAPI.php';
$apiKey = 'YOUR_API_KEY';
$package = 'WS25'; // Package: WS1 - WS25
$useSSL = false; // Use HTTP or HTTPS (Secure, but slower)
$ip = '8.8.8.8';
// Initialize
$location = new IP2LocationAPI($apiKey, $package, $useSSL);
/*
Translate country, region, and city name to desired language.
Refer to product page for available language code.
*/
$location->setLanguage('zh-cn');
/*
Enable add ons to display more result.
Refer to product page for available add ons.
*/
$location->setAddOns([
'continent', 'country', 'region', 'city', 'geotargeting', 'country_groupings', 'time_zone_info',
]);
// Start query
if (!$location->query($ip)) {
die('ERROR');
}
echo '<pre>';
echo 'Country Code : ' . $location->countryCode . "\n";
echo 'Country Name : ' . $location->countryName . "\n";
echo 'Region Name : ' . $location->regionName . "\n";
echo 'City Name : ' . $location->cityName . "\n";
echo 'Latitude : ' . $location->latitude . "\n";
echo 'Longitude : ' . $location->longitude . "\n";
echo 'ZIP Code : ' . $location->zipCode . "\n";
echo 'Time Zone : ' . $location->timeZone . "\n";
echo 'ISP : ' . $location->isp . "\n";
echo 'Domain : ' . $location->domain . "\n";
echo 'Latitude : ' . $location->netSpeed . "\n";
echo 'IDD Code : ' . $location->iddCode . "\n";
echo 'Area Code : ' . $location->areaCode . "\n";
echo 'Weather Station Code : ' . $location->weatherStationCode . "\n";
echo 'Weather Station Name : ' . $location->weatherStationName . "\n";
echo 'Mobile Brand : ' . $location->mobileBrand . "\n";
echo 'Elevation : ' . $location->elevation . "\n";
echo 'Usage Type : ' . $location->usageType . "\n\n";
if ($location->continent) {
echo 'Continent Name : ' . $location->continent['name'] . "\n";
echo 'Continent Code : ' . $location->continent['code'] . "\n";
echo 'Hemisphere : ' . $location->continent['hemisphere'] . "\n";
echo 'Localize Name : ' . $location->continent['translated'] . "\n\n";
}
if ($location->country) {
echo 'Country Name : ' . $location->country['name'] . "\n";
echo 'Localize Name : ' . $location->country['translated'] . "\n";
echo 'Alpha 3 Code : ' . $location->country['alpha3Code'] . "\n";
echo 'Numeric Code : ' . $location->country['numericCode'] . "\n";
echo 'Demonym : ' . $location->country['demonym'] . "\n";
echo 'Flag : ' . $location->country['flag'] . "\n";
echo 'Capital : ' . $location->country['capital'] . "\n";
echo 'Total Area : ' . $location->country['totalArea'] . "\n";
echo 'Population : ' . $location->country['population'] . "\n";
echo 'Currency : ' . $location->country['currencyName'] . ' (' . $location->country['currencyCode'] . ', ' . $location->country['currencySymbol'] . ')' . "\n";
echo 'Language : ' . $location->country['languageName'] . ' (' . $location->country['languageCode'] . ')' . "\n";
echo 'IDD Code : ' . $location->country['iddCode'] . "\n";
echo 'TLD : ' . $location->country['tld'] . "\n\n";
}
if ($location->region) {
echo 'Region Name : ' . $location->region['name'] . "\n";
echo 'Localize Name : ' . $location->region['translated'] . "\n";
echo 'Region Code : ' . $location->region['code'] . "\n\n";
}
if ($location->city) {
echo 'City Name : ' . $location->city['name'] . "\n";
echo 'Localize Name : ' . $location->city['translated'] . "\n\n";
}
if ($location->geotargeting) {
echo 'Metro Code : ' . $location->geotargeting['metro'] . "\n\n";
}
if ($location->countryGroupings) {
foreach ($location->countryGroupings as $group) {
echo 'Group of : ' . $group->name . ' (' . $group->acronym . ')' . "\n";
}
echo "\n";
}
if ($location->timeZoneInfo) {
echo 'Olson : ' . $location->timeZoneInfo['olson'] . "\n";
echo 'Current Time : ' . $location->timeZoneInfo['currentTime'] . "\n";
echo 'GMT Offset : ' . $location->timeZoneInfo['gmtOffset'] . "\n";
echo 'DST : ' . $location->timeZoneInfo['isDST'] . "\n";
}
echo '</pre>';