如何以编程方式使用php发送特定的http状态代码? 是否有任何方法甚至是一个类?
答案 0 :(得分:1)
答案 1 :(得分:1)
header()
功能是您所需要的。
void header ( string $string [, bool $replace = true [, int $http_response_code ]] )
将其放在脚本的第一个<?php
标记之后,以呈现响应输出。
答案 2 :(得分:0)
在之前发送header()
,然后向客户端发送任何其他内容。一些可能的状态标题如下:
header('HTTP/1.1 200 OK');
// Page was not found:
header('HTTP/1.1 404 Not Found');
// Access forbidden:
header('HTTP/1.1 403 Forbidden');
// The page moved permanently should be used for
// all redrictions, because search engines know
// what's going on and can easily update their urls.
header('HTTP/1.1 301 Moved Permanently');
// Server error
header('HTTP/1.1 500 Internal Server Error');
// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');