There is a problem. The code in the middle of the page finds that there is no ID. how can I get the 404 status code returned?

Source: Internet
Author: User
There is a problem. The code in the middle of the page finds that there is no ID. how can I get the 404 status code returned? As you know, output 404 depends on the header. Generally, the first header (404... similar.
However, when some logic code is encountered, the client 404 error must be returned only when the source code is output.
How can I brake and return a 404 status code to the client?


Reply to discussion (solution)

The same!
Header ("HTTP/1.0 404 Not Found ");

If your php> = 5.4 is written anywhere, it will not be wrong.
Otherwise, you may need to add

The idea of the moderator is correct.

Complete

First enable ob_start ();
..
..
..
Logic code
..
..
..
// Output 404
Ob_clean (); // destroy everything before
Header ("HTTP/1.1 404 Not Found ");
Ob_end_flush (); // output all content to the browser
Exit ();

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.