From 64f20fcc81e36eec2687f14b53d354fe557bcffc Mon Sep 17 00:00:00 2001 From: T2cc <5152438+gtguizhou@user.noreply.gitee.com> Date: Tue, 22 Jun 2021 02:30:59 +0000 Subject: [PATCH] =?UTF-8?q?cors=20=E6=A3=80=E6=B5=8B=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E4=B8=8D=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8=20exit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/application/common.php b/application/common.php index fa160030b..a2cc403b5 100755 --- a/application/common.php +++ b/application/common.php @@ -431,8 +431,8 @@ if (!function_exists('check_cors_request')) { if (in_array("*", $domainArr) || in_array($_SERVER['HTTP_ORIGIN'], $domainArr) || (isset($info['host']) && in_array($info['host'], $domainArr))) { header("Access-Control-Allow-Origin: " . $_SERVER['HTTP_ORIGIN']); } else { - header('HTTP/1.1 403 Forbidden'); - exit; + $response = Response::create('cors 检测无效', 'html', 403); + throw new HttpResponseException($response); } header('Access-Control-Allow-Credentials: true'); @@ -445,7 +445,8 @@ if (!function_exists('check_cors_request')) { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); } - exit; + $response = Response::create('', 'json'); + throw new HttpResponseException($response); } } } @@ -474,7 +475,8 @@ if (!function_exists('check_ip_allowed')) { $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; + $response = Response::create('ip 无权访问', 'html', 403); + throw new HttpResponseException($response); } } } -- Gitee