|
@@ -460,3 +460,21 @@ if (!function_exists('xss_clean')) {
|
|
|
return \app\common\library\Security::instance()->xss_clean($content, $is_image);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+if (!function_exists('check_ip_allowed')) {
|
|
|
+
|
|
|
+ * 检测IP是否允许
|
|
|
+ * @param string $ip IP地址
|
|
|
+ */
|
|
|
+ function check_ip_allowed($ip = null)
|
|
|
+ {
|
|
|
+ $ip = is_null($ip) ? request()->ip() : $ip;
|
|
|
+ $forbiddenipArr = config('site.forbiddenip');
|
|
|
+ $forbiddenipArr = !$forbiddenipArr ? [] : $forbiddenipArr;
|
|
|
+ $forbiddenipArr = is_array($forbiddenipArr) ? $forbiddenipArr : array_filter(explode("\n", str_replace("\r\n", "\n", $forbiddenipArr)));
|
|
|
+ if ($forbiddenipArr && \Symfony\Component\HttpFoundation\IpUtils::checkIp($ip, $forbiddenipArr)) {
|
|
|
+ header('HTTP/1.1 403 Forbidden');
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|