可能重复:
return a specific http status code with php如何在PHP中返回http statuscodes?
我如何以编程方式发送特定的HTTP statuscodes用PHP? 有没有任何方法,甚至是类?
可能重复:
return a specific http status code with php如何在PHP中返回http statuscodes?
我如何以编程方式发送特定的HTTP statuscodes用PHP? 有没有任何方法,甚至是类?
header()
函数是你所需要的。
void header (string $string [, bool $replace = true [, int $http_response_code ]])
把它放在右后第一<?php
标记为脚本呈现响应输出。
发送您发送任何东西给客户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');
请参阅http://stackoverflow.com/a/6164319/1395993以获得详细的答案。 –