Home > php教程 > php手册 > body text

php header 404错误包含文件出现乱码

WBOY
Release: 2016-05-25 16:52:09
Original
1361 people have browsed it

通常在通过php判断一个不存在的资源(比如category、product不存在)时需要通过header返回一个404的状态并显示相应的404页面,在之前的服务器上写法如下:

header('HTTP/1.1 404 Not Found');  
header('Status: 404 Not Found');  
require('404.php');  
exit();
Copy after login

但是换了新的服务器发现页面上出现一些字母+数字的乱码,检查后发现当前server的请求页面时通信协议的版本和代码中的HTTP/1.1不一致,要想知道当前server的通信协议的名称和版本可以用$_SERVER['SERVER_PROTOCOL'] ,经测试我server的http版本是1.0,所以代码要修改为:

header('HTTP/1.0 404 Not Found');  
header('Status: 404 Not Found');  
require('error.php');  
exit();
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template