-2

可能重复:
使用 php 返回特定的 http 状态代码

如何以编程方式使用 php 发送特定的 http 状态码?是否有任何方法甚至是一个类?

4

3 回答 3

1

header()功能是您所需要的。

void header ( string $string [, bool $replace = true [, int $http_response_code ]] )

将其<?php放在呈现响应输出的脚本的第一个标记之后。

你应该参考http://php.net/manual/en/function.header.php

于 2012-10-16T11:26:49.447 回答
1

header()功能:

header('HTTP/1.0 404 Not Found');

将它放在脚本的任何输出之前。

于 2012-10-16T11:25:21.057 回答
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');
于 2012-10-16T11:26:56.110 回答