-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIP.php
50 lines (43 loc) · 1.59 KB
/
IP.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
<?php
class Evil_IP extends Zend_Controller_Plugin_Abstract
{
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$this->defineIP();
}
private function defineIP()
{
if(false == defined('_IP'))
{
if (isset($_SERVER['HTTP_X_REAL_IP']))
define ('_IP', $_SERVER['HTTP_X_REAL_IP']);
else
define ('_IP', (isset($_SERVER['REMOTE_ADDR']))?$_SERVER['REMOTE_ADDR']:'');
}
}
public static function geoIP()
{
switch (APPLICATION_ENV)
{
case 'production':
if (preg_match('@127\.*@', _IP
or preg_match('@10\.*@', _IP)
or preg_match('@172\.*@', _IP))
or preg_match('@192\.168\.*@', _IP)
or _IP == '127.0.0.1')
$result = 'LO';
else
$result = geoip_country_code_by_name(_IP);
break;
case 'development':
$countries = array('74.125.43.103','86.134.153.24','86.122.153.245');
$result = geoip_country_code_by_name($countries[array_rand($countries)]);
break;
case 'testing':
$countries = array('US', 'CN', 'RU', 'RO', 'GN');
$result = $countries[array_rand($countries)];
break;
}
return $result;
}
}