PHP returns 404 status Code, processed by the server

Source: Internet
Author: User

1. Implemented by the header () method,

The simplest way, and there's no limit to the PHP version.

<?php

Header (' http/1.1 404 Not Found ');

Header ("status:404 not Found");

?>

When the server is set to 404 pages, access to the PHP will automatically return 404 status and 404 pages.

2. Using the Http_response_code () method,

If your PHP version is greater than 5.4, you can use this new method

<?php

Http_response_code (404);

?>

Note : If your version is less than 5.4, but you have to use Http_response_code (), here is the code for this method

1<?PHP2 3     if(!function_exists(' Http_response_code ')) {4         functionHttp_response_code ($code=NULL) {5 6             if($code!==NULL) {7 8                 Switch($code) {9                      Case100:$text= ' Continue '; Break;Ten                      Case101:$text= ' switching protocols '; Break; One                      Case200:$text= ' OK '; Break; A                      Case201:$text= ' Created '; Break; -                      Case202:$text= ' Accepted '; Break; -                      Case203:$text= ' non-authoritative information '; Break; the                      Case204:$text= ' No Content '; Break; -                      Case205:$text= ' Reset Content '; Break; -                      Case206:$text= ' Partial Content '; Break; -                      Case300:$text= ' Multiple Choices '; Break; +                      Case301:$text= ' Moved permanently '; Break; -                      Case302:$text= ' Moved temporarily '; Break; +                      Case303:$text= ' See other '; Break; A                      Case304:$text= ' Not Modified '; Break; at                      Case305:$text= ' Use Proxy '; Break; -                      Case400:$text= ' Bad Request '; Break; -                      Case401:$text= ' unauthorized '; Break; -                      Case402:$text= ' Payment Required '; Break; -                      Case403:$text= ' Forbidden '; Break; -                      Case404:$text= ' Not Found '; Break; in                      Case405:$text= ' Method not allowed '; Break; -                      Case406:$text= ' not acceptable '; Break; to                      Case407:$text= ' Proxy authentication Required '; Break; +                      Case408:$text= ' Request time-out '; Break; -                      Case409:$text= ' Conflict '; Break; the                      Case410:$text= ' Gone '; Break; *                      Case411:$text= ' Length Required '; Break; $                      Case412:$text= ' precondition Failed '; Break;Panax Notoginseng                      Case413:$text= ' Request Entity Too Large '; Break; -                      Case414:$text= ' Request-uri Too Large '; Break; the                      Case415:$text= ' Unsupported Media Type '; Break; +                      Case500:$text= ' Internal Server Error '; Break; A                      Case501:$text= ' not implemented '; Break; the                      Case502:$text= ' Bad Gateway '; Break; +                      Case503:$text= ' Service unavailable '; Break; -                      Case504:$text= ' Gateway time-out '; Break; $                      Case505:$text= ' HTTP Version not supported '; Break; $                     default: -                         Exit(' Unknown HTTP status code '.htmlentities($code) . ‘"‘); -                      Break; the                 } - Wuyi                 $protocol= (isset($_server[' Server_protocol ']) ?$_server[' Server_protocol ']: ' http/1.0 '); the  -                 Header($protocol. ‘ ‘ .$code. ‘ ‘ .$text); Wu  -                 $GLOBALS[' http_response_code '] =$code; About  $}Else { -  -                 $code= (isset($GLOBALS[' Http_response_code ']) ?$GLOBALS[' Http_response_code ']: 200); -  A             } +  the             return $code; -  $         } the     } the  the?>
View Code

PHP returns 404 status Code, processed by the server

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.