Php header 404 jump error page instance

Source: Internet
Author: User

First, let's look at the header function.

The header () function sends the original HTTP header to the client, header (string, replace, http_response_code)

Php header 404:

Php code

 

The code is as follows: Copy code
Header ("HTTP/1.1 404 Not Found"); exit;

If the above code is ineffective, try the following code:

Php code
 

The code is as follows: Copy code
Header ("Status: 404 Not Found ");


The above page is only in the 404 status. If we want to verify it, we need to perform the following operations:

The code is as follows: Copy code

@ Header ("http/1.1 404 not found ");
@ Header ("status: 404 not found ");
Include ("404.html"); // jump to a page. This method is recommended.
Exit ();

In this way, there will be both an error message and a beautiful page.

The code is as follows: Copy code


Function getref ()
{
$ Url = @ $ _ SERVER ['http _ referer'];
If (! Empty ($ url ))
 {
If (! Strstr ($ url, '111cn. Net ')&&! Strstr ($ url, '111cn. Net '))
  {
@ Header ("http/1.1 404 not found ");
@ Header ("status: 404 not found ");
Include ("404.html"); // jump to a page. This method is recommended.
Exit ();
  }
 }
Else
 {
@ Header ("http/1.1 404 not found ");
@ Header ("status: 404 not found ");
Include ("404.html"); // jump to a page. This method is recommended.
Exit ();
 }
}

Apache is much simpler, ErrorDocument 404/404 .html

Note: After writing the code, you must use the topic 404 error page tool for testing. Otherwise, it may be difficult to return the code 200. You must check that the code is in the 404 status.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.