新增maxmind数据库本地判断国家,并且将优先级调整至最高

This commit is contained in:
root
2026-06-14 15:29:29 +08:00
parent 72d388f642
commit eab59c1c18
17 changed files with 912 additions and 38 deletions
+11 -35
View File
@@ -32,10 +32,9 @@ class visitorInfo
*/
public function get_visitor_Info($costm_ip_score = '', $check_key = '', $check_country = '')
{
$this->v_country = !empty($_SESSION["gcu_country"])?$_SESSION["gcu_country"]:$check_country;
$this->v_country = !empty($_SESSION['gcu_country']) ? (string) $_SESSION['gcu_country'] : '';
$this->v_ip = $this->getIp();
$this->v_Browser = $this->getBrowser();
//$this->v_country = $this->findCityByIp($this->v_ip);
$this->v_referer = $this->getFromPage();
$this->v_Client = $this->v_isMobile();
$this->v_curPageURL = $this->curPageURL();
@@ -45,8 +44,10 @@ class visitorInfo
$this->costm_ip_score = $costm_ip_score;
$this->check_key = $check_key;
$this->check_country = $check_country;
$_SESSION["gcu_country"] = $this->v_country;
if ($this->v_country !== '') {
$_SESSION['gcu_country'] = $this->v_country;
}
$_SESSION["gcu_Client"] = $this->v_Client;
$_SESSION["gcu_ip"] = $this->v_ip;
$_SESSION["gcu_Browser"] = $this->v_Browser;
@@ -71,7 +72,9 @@ class visitorInfo
$return = ['result' => false, 'reason' => 'API响应异常', 'country' => $this->v_country];
}
$this->check_result = !empty($return['result']) ? "true" : "false";
$this->v_country = isset($return['country']) ? $return['country'] : $this->v_country;
if ($this->v_country === '' && !empty($return['country'])) {
$this->v_country = (string) $return['country'];
}
$this->v_reason = cloak_api_reason($return, $this->check_result);
return $return;
}
@@ -149,37 +152,10 @@ class visitorInfo
//获取访客ip
public function getIp($type = 0)
{
$type = $type ? 1 : 0;
static $ip = NULL;
if ($ip !== NULL) return $ip[$type];
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { // 使用cloudflare 转发的IP地址
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} else {
if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$ip = getenv('REMOTE_ADDR');
} elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$ip = $_SERVER['REMOTE_ADDR'];
}
if ($type) {
return ClientIpResolver::resolve();
}
// if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
// $pos = array_search('unknown',$arr);
// if(false !== $pos) unset($arr[$pos]);
// $ip = trim($arr[0]);
// }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
// $ip = $_SERVER['HTTP_CLIENT_IP'];
// }elseif (isset($_SERVER['REMOTE_ADDR'])) {
// $ip = $_SERVER['REMOTE_ADDR'];
// }
// IP地址合法验证
//$long = sprintf("%u",ip2long($ip));
//$ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
return $ip;
return ClientIpResolver::resolve();
}
//客户当前浏览的页面 url(浏览器实际访问地址,含正确 scheme 与 query