-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGeoip.php
More file actions
executable file
·94 lines (78 loc) · 2.18 KB
/
Geoip.php
File metadata and controls
executable file
·94 lines (78 loc) · 2.18 KB
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
<?php (defined('BASEPATH') OR defined('SYSPATH')) or die('No direct access allowed.');
/**
* Geoip Location Online Class using api of ipinfodb.com
*
* @package CodeIgniter
* @subpackage Application/Libraries
* @category Libraries
* @resource api.ipinfodb.com
* @autor Ariel Marti
*
* Instructions in readme
Recuerda que si la clave no funciona, obtenla en http://www.ipinfodb.com/
Remember if the key doesn't work, get in http://www.ipinfodb.com/
*
* $this->load->library('geoip');
* $this->geoip->geolocalization("181.110.XXX.XXX");
* echo $this->geoip->info->countryName; //return Argentina
* echo $this->geoip->info->cityName; //return Buenos Aires
*
* RETURNED DATA JSON OBJECT
*{
* "statusCode" : "OK",
* "statusMessage" : "",
* "ipAddress" : "181.110.XXX.XXX",
* "countryCode" : "AR",
* "countryName" : "Argentina",
* "regionName" : "Distrito Federal",
* "cityName" : "Buenos Aires",
* "zipCode" : "1871",
* "latitude" : "35.6552",
* "longitude" : "-31.57*2",
* "timeZone" : "-03:00"
*}
*/
// ------------------------------------------------------------------------
class Geoip{
//CI
protected $CI;
protected $_gi;
//CLASS
protected $_Ip;
protected $_Data;
//Clave Obtenida | Key obtained.
protected $_key = "48e9a12e7c98df764fca3b69ec790aa799bcf34dc14e42aa2925ef870fd5d22b";
function __construct()
{
if (!isset($this->CI))
{
$this->CI =& get_instance();
}
}
function __destruct() {
if (isset($this->_gi))
{
geoip_close($this->_gi);
}
}
function geolocalization($ip = null)
{
if ($this->_Set_IP($ip)) {
$this->_Data = json_decode(file_get_contents("http://api.ipinfodb.com/v3/ip-city/?key=$this->_key&ip=$ip&format=json"));
return true;
}
else
return false;
}
function info() {
return $this->_Data;
}
private function _Set_IP($ip=null){
if($ip==null)
{
$ip = $this->CI->input->ip_address();
}
$this->_Ip = $ip;
return $this->CI->input->valid_ip($this->_Ip);
}
}