-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
53 lines (49 loc) · 2.26 KB
/
index.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
<?php
include 'php/useragent.class.php';
require_once 'php/reader.php';
$useragent = UserAgentFactory::analyze($_SERVER['HTTP_USER_AGENT']);
/*
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
*/
// $db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::SHARED_MEMORY);
/*
Cache the database into memory to accelerate lookup speed
WARNING: Please make sure your system have sufficient RAM to enable this feature
*/
// $db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::MEMORY_CACHE);
/*
Default file I/O lookup
*/
if (!empty($_SERVER["HTTP_CLIENT_IP"])){
//check for ip from share internet
$ip = $_SERVER["HTTP_CLIENT_IP"];}
elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
// Check for the Proxy User
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];}
else{
$ip = $_SERVER["REMOTE_ADDR"];}
// This will print user's real IP Address
// does't matter if user using proxy or not.
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$db = new \IP2Location\Database('src/ipv4/ipv4.bin', \IP2Location\Database::MEMORY_CACHE);}
else {
$db = new \IP2Location\Database('src/ipv6/ipv6.bin', \IP2Location\Database::MEMORY_CACHE);}
$records = $db->lookup($ip, \IP2Location\Database::ALL);
echo '<pre>';
echo 'User Agent : ' . $useragent->useragent . "\n";
echo 'System : ' . $useragent->os['title'] . "\n";
echo 'Browser : ' . $useragent->browser['title'] . "\n";
echo 'IP Version : ' . $records['ipVersion'] . "\n";
echo 'IP Address : ' . $records['ipAddress'] . "\n";
echo 'Country Code : ' . $records['countryCode'] . "\n";
echo 'Country Name : ' . $records['countryName'] . "\n";
echo 'Region Name : ' . $records['regionName'] . "\n";
echo 'City Name : ' . $records['cityName'] . "\n";
echo 'Latitude : ' . $records['latitude'] . "\n";
echo 'Longitude : ' . $records['longitude'] . "\n";
echo 'Time Zone : ' . $records['timeZone'] . "\n";
echo 'ZIP Code : ' . $records['zipCode'] . "\n";
echo 'ISP Name : ' .gethostbyaddr($ip) . "\n";
echo '</pre>';
?>