php的header返回503状态码

无忧主机PHP空间

5.3以下版本用兼容写法:


if(!function_exists('http_response_code')) {

        functionhttp_response_code($code= NULL) {
 
            if($code!== NULL) {
 
                switch($code) {
                    case100:$text='Continue';break;
                    case101:$text='Switching Protocols';break;
                    case200:$text='OK';break;
                    case201:$text='Created';break;
                    case202:$text='Accepted';break;
                    case203:$text='Non-Authoritative Information';break;
                    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;
                    case304:$text='Not Modified';break;
                    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;
                    case405:$text='Method Not Allowed';break;
                    case406:$text='Not Acceptable';break;
                    case407:$text='Proxy Authentication Required';break;
                    case408:$text='Request Time-out';break;
                    case409:$text='Conflict';break;
                    case410:$text='Gone';break;
                    case411:$text='Length Required';break;
                    case412:$text='Precondition Failed';break;
                    case413:$text='Request Entity Too Large';break;
                    case414:$text='Request-URI Too Large';break;
                    case415:$text='Unsupported Media Type';break;
                    case500:$text='Internal Server Error';break;
                    case501:$text='Not Implemented';break;
                    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;
                }
 
                $protocol= (isset($_SERVER['SERVER_PROTOCOL']) ?$_SERVER['SERVER_PROTOCOL'] :'HTTP/1.0');
 
                header($protocol.' '.$code.' '.$text);
 
                $GLOBALS['http_response_code'] =$code;
 
            }else{
 
                $code= (isset($GLOBALS['http_response_code']) ?$GLOBALS['http_response_code'] : 200);
 
            }
 
            return$code;
 
        }
    }

你可能感兴趣的:(php的header返回503状态码)