可能重複:
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以獲得詳細的答案。 –