tp6跨域访问最新写法

tp6跨域访问最新写法

   public function handle($request, Closure $next, ? array $header = [])
    {
    
       
        $header = !empty($header) ? array_merge($this->header, $header) : $this->header;

        if (!isset($header['Access-Control-Allow-Origin'])) {
            $origin = $request->header('origin');

            if ($origin && ('' == $this->cookieDomain || strpos($origin, $this->cookieDomain))) {
                $header['Access-Control-Allow-Origin'] = $origin;
            } else {
                $header['Access-Control-Allow-Origin'] = '*';
            }
        }
        if ($request->method() == 'OPTIONS') {
            $response = response('');
        } else {
            $response = $next($request);
        }
  
     
        return $response->header($header);
    }
posted @ 2023-03-27 17:23  newmiracle宇宙  阅读(337)  评论(0编辑  收藏  举报