Skip to main content

set_header

Function set_header 

Source
pub fn set_header(header: &str) -> Result<()>
Expand description

Sets a response header and removes the headers with the same name, like header($header).

header is a full line, for example "Content-Type: text/plain". PHP applies its usual rules: a Location header sets the status to 302 (or 303 for a non GET/HEAD request) unless it is already 201 or 3xx, and an HTTP/ line sets the status line. Call set_response_code after a Location header to send another redirect code.

ยงErrors

Error::ResponseHeaderFailed if no request is active (for example during MINIT), if a SapiGlobals guard is alive, if header is empty, or if PHP refuses the header. PHP emits a warning when the headers are already sent or when header contains a new line or a NUL byte.