Home > Backend Development > PHP Tutorial > Solution to php header 404 error containing garbled files_PHP tutorial

Solution to php header 404 error containing garbled files_PHP tutorial

WBOY
Release: 2016-07-13 10:57:26
Original
1115 people have browsed it

This article will introduce to you the solution to the php header 404 error containing garbled files. Students who have encountered such problems can refer to it for reference.

Usually when you use PHP to determine a non-existent resource (such as category or product does not exist), you need to return a 404 status through the header and display the corresponding 404 page. On the previous server, it was written as follows:

header('Status: 404 Not Found');
The code is as follows
 代码如下 复制代码

header('HTTP/1.1 404 Not Found'); 

header('Status: 404 Not Found'); 

require('404.php'); 

exit(); 

Copy code


header('HTTP/1.1 404 Not Found');
 代码如下 复制代码

header('HTTP/1.0 404 Not Found'); 

header('Status: 404 Not Found'); 

require('error.php'); 

exit();

require('404.php');

exit();

However, after switching to a new server, I found that there were some garbled letters and numbers on the page. After checking, I found that the version of the communication protocol when requesting the page of the current server was inconsistent with the HTTP/1.1 in the code. If you want to know the name of the communication protocol of the current server and The version can be $_SERVER['SERVER_PROTOCOL']. After testing, the http version of my server is 1.0, so the code needs to be modified to:
The code is as follows Copy code
header('HTTP/1.0 404 Not Found'); header('Status: 404 Not Found'); require('error.php');
exit();
http://www.bkjia.com/PHPjc/632099.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632099.htmlTechArticleThis article will introduce to you the solution to the php header 404 error containing garbled files. Anyone who has encountered such a problem Students can enter for reference. Usually when judging a non-existent one through php...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template