HTTP 303 See Other 状态代码告诉浏览器可以在不同的位置找到请求的响应,新位置应在位置标头中提供。
不要将此用于重定向。
如果移动了页面,则应改为使用 301 响应代码。
以下是 303 See Other 重定向的示例:
HTTP/1.1 303 See Other Location: http://onitroad.com/
为了使用 PHP 传递 303 响应,我们可以使用 header 函数编写一个简单的单行代码:
header("Location: https://example.com/",TRUE,303);
使用PHP发送 303 响应代码的更多方法
一种更易读的方法是使用 http_response_code ,这样我们就不必记住头函数中参数的顺序:
http_response_code(303); header('Location: https://example.com/');
要改为发送原始标头,我们需要确保使用正确的协议,并非常小心不要拼错标头:
header(set_protocol() . ' 303 See Other'); header('Location: https://example.com/'); function set_protocol() { $supported_protocols = array( 'HTTP/2.0' => true, 'HTTP/1.1' => true, 'HTTP/1.0' => true, ); $protocol = $_SERVER["SERVER_PROTOCOL"]; if (!isset($supported_protocols["$protocol"])) { $protocol = 'HTTP/1.0'; } return $protocol; }
日期:2020-06-02 22:17:26 来源:oir作者:oir