Home > Backend Development > PHP Problem > How to jump to 404 in php

How to jump to 404 in php

藏色散人
Release: 2023-03-05 16:50:01
Original
4709 people have browsed it

How to implement php jump to 404: first open the corresponding PHP file; then add the code as "@header("http/1.1 404 not found");"; finally output the error page directly through echo. Can jump.

How to jump to 404 in php

Recommended: "PHP Video Tutorial"

How to implement php jump to 404:

Every website basically has the 404 page. The function of the 404 page is to prevent users from accessing your website. When a page does not exist or is inaccessible, a friendly and clear reply is given to the current user through the 404 page. Tell him that the address does not exist and tell him what to do next.

In PHP programs, we often need to consider how to use PHP to write 404 page jumps. The author below will share with you how to use PHP to write 404 redirects!

@header("http/1.1 404 not found");
@header("status: 404 not found");
echo 'echo 404';//直接输出页面错误信息
exit();
Copy after login

Or:

@header("http/1.1 404 not found");
@header("status: 404 not found");
include("http://www.phpernote.com/404.html");
//跳转到某一个页面,推荐使用这种方法,注意include文件的路径不能是网络路径
exit();
Copy after login

To check whether the 404 setting is successful, you can use the firebug plug-in of firefox to check. The specific checking method is as follows:

If firebug has been installed Next, use Firefox browser to open the page where you want to check the 404 status code, click the bug icon in the lower right corner, start the "Network" tab, and open "Network-All/html-headers" in order; if everything is normal, you can see Various page parameters including headers and responses.

In addition, here is the definition of the apache 404 error page. The specific definition method is as follows:

Create a new .htaccess file in the root directory of the website, and then Just add the following content to the file:

ErrorDocument 404 http://www.phpernote.com/404.html
Copy after login

The above is the detailed content of How to jump to 404 in php. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template