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://...");
How can I archive this?
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)
Multiple header
Docs calls:
header("Location: ....");
header("Header2: ....");
header("Header3: ....");
...
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.
Commonly, HTTP clients do not offer any such options, that is most HTTP clients do not turn response headers into request headers in case one of the response headers is a Location:
header and a status code in the 3xx range.
This would not make any sense anyway as such practice would be unsafe.
Especially on the level of interactive HTTP clients (like a browser) that automatically perform redirects without approval of the user. See HTTP, compare Fetch API.
Further reading: https://ec.haxx.se/http/http-redirects
An exclusion to the rules of the game outlined above is HTTP state management ¹ that most browsers support. E.g. you can respond with a cookie and the redirect request then sets the cookie. You perhaps might want to combine that with PHP session management. ²