First commit
This commit is contained in:
35
uc_server/lib/ucip_getter_dnslist.class.php
Normal file
35
uc_server/lib/ucip_getter_dnslist.class.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
[UCenter] (C)2001-2099 Comsenz Inc.
|
||||
This is NOT a freeware, use is subject to license terms
|
||||
|
||||
$Id: ucip_getter_dnslist.class.php 969 2019-12-19 12:00:00Z community $
|
||||
*/
|
||||
|
||||
class ucip_getter_dnslist {
|
||||
|
||||
public static function get($s) {
|
||||
if (empty($s['header']) || empty($s['list'])) {
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$rdns = gethostbyaddr($ip);
|
||||
foreach($s['list'] as $host) {
|
||||
if (preg_match('/'.$host.'$/i', $rdns)) {
|
||||
if ($s['header'] != 'HTTP_X_FORWARDED_FOR') {
|
||||
$ip = ucip::validate_ip($_SERVER[$s['header']]) ? $_SERVER[$s['header']] : $ip;
|
||||
} else {
|
||||
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",") > 0) {
|
||||
$exp = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
$ip = ucip::validate_ip(trim($exp[0])) ? $exp[0] : $ip;
|
||||
} else {
|
||||
$ip = ucip::validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user