重定向到页面并发送自定义 HTTP 标头 [英] Redirect to page and send custom HTTP headers
问题描述
我使用以下代码重定向到 PHP 页面.我需要设置一个自定义 HTTP 标头以与重定向一起传递.
I use the following code to redirect to a page in PHP. I need to set a custom HTTP headers to pass along with the redirect.
header("Location: http://...");
我该如何存档?
推荐答案
这个问题需要有不同的回答,因为你看的地方不同,答案也不同:
This question needs to be answered differently as depending from where you're looking the answer is different:
就您关心的重定向响应而言(而不是重定向响应可能触发的请求)
As far as you're concerned about the redirect response (and not the request that may be triggered by a redirect response)
多个header
文档 调用:
header("Location: ....");
header("Header2: ....");
header("Header3: ....");
...
由重定向响应触发的新请求(浏览器、HTTP 客户端)
如果您正在寻找由重定向响应触发的新请求,请查阅您的 HTTP 客户端技术文档以了解您的选择.
New Request triggered by a Redirect Response (Browser, HTTP client)
If you're looking for the new request that has been triggered by a redirect response, please consult your HTTP clients technical documentation for your options.
通常 HTTP 客户端不提供任何此类选项,大多数 HTTP 客户端不会将响应标头转换为请求标头,以防其中一个响应标头是 Location:
标头.
Commonly HTTP clients do not offer any such options, most HTTP clients do not turn response headers into request headers in case one of the response headers is a Location:
header.
无论如何这没有任何意义,因为这种做法是不安全的.
This would not make any sense anyway as such practice would be unsafe.
特别是在交互式 HTTP 客户端(如浏览器)级别上,无需用户批准即可自动执行重定向.
Especially on the level of interactive HTTP clients (like a browser) that automatically perform redirects without approval of the user.
进一步阅读:https://ec.haxx.se/http/http-redirects
这篇关于重定向到页面并发送自定义 HTTP 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!