Quick Answer
header() sends raw HTTP headers to the browser. Must be called before any output. Used for: redirects (Location header), setting content type (Content-Type: application/json), caching headers (Cache-Control), file download prompts (Content-Disposition). Always call exit after a redirect header to stop script execution immediately.
Answer
header() sends raw HTTP headers for redirects, JSON output, or content-type changes and must run before output.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.
PHP interview questions and answers for beginner, junior, mid-level, senior, and expert developers. Ideal for freshers and experienced candidates preparing for PHP roles.