update getallheaders

This commit is contained in:
franknstayn
2021-12-01 19:37:10 +08:00
parent 9ed77a3451
commit 2fb3fe6f52

View File

@@ -14,23 +14,27 @@ class isAuthorized
* @param \Closure $next * @param \Closure $next
* @return mixed * @return mixed
*/ */
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
if (isset(getallheaders()['token']) && getallheaders()['token'] == "1HHIaIsT4pvO2S39vMzlVfGWi3AhAz6F5xGBNKil") {
function getheaders()
{
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
if (isset(getheaders()['Token']) && getheaders()['Token'] == "1HHIaIsT4pvO2S39vMzlVfGWi3AhAz6F5xGBNKil") {
return $next($request); return $next($request);
} else { } else {
return response()->json(['status' => false, 'error' => "Invalid request"], 503); return response()->json(['status' => false, 'error' => "Invalid request"], 503);
} }
} }
function getallheaders()
{
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
} }