Home > Backend Development > PHP Tutorial > nginx + php7.0 返回状态码永远是200

nginx + php7.0 返回状态码永远是200

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:14:28
Original
1423 people have browsed it

在windows上配置好了nginx+php的环境
但是在php中通过

<code>header('http/1.1 403 Forbidden');
</code>
Copy after login
Copy after login

来尝试返回403缺没用,看浏览器接收到header,状态码却是200。再尝试了

<code>http_response_code(403);
</code>
Copy after login
Copy after login

或者laravel的

<code>Response::json($res,403);
</code>
Copy after login
Copy after login

全部都无效,永永远远地返回200的状态码?这是怎么回事?怎么才可以改变状态码?

回复内容:

在windows上配置好了nginx+php的环境
但是在php中通过

<code>header('http/1.1 403 Forbidden');
</code>
Copy after login
Copy after login

来尝试返回403缺没用,看浏览器接收到header,状态码却是200。再尝试了

<code>http_response_code(403);
</code>
Copy after login
Copy after login

或者laravel的

<code>Response::json($res,403);
</code>
Copy after login
Copy after login

全部都无效,永永远远地返回200的状态码?这是怎么回事?怎么才可以改变状态码?

LZ你好,我刚刚试过我的环境,没问题,估计是你Laravel中调错了。

实验1:

<code>//test.php
<?php header('http/1.1 403 Forbidden');</code></code>
Copy after login

浏览器测试:
nginx + php7.0 返回状态码永远是200

实验2:
在Laravel的IndexController.php中新建test动作

<code>public function test(){
        return (new Response('页面禁止访问', 403))->header('Content-Type', 'text/html');
    } </code>
Copy after login

浏览器测试:
nginx + php7.0 返回状态码永远是200

把php.ini里面的

<code>cgi.rfc2616_headers = 1;</code>
Copy after login

改成

<code>cgi.rfc2616_headers = 0;</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template