1. Home
  2. Computer Science MCQs
  3. PHP
  4. What is the purpose of the header() function in PHP?

Added 23 Jan 2024

What is the purpose of the header() function in PHP?

  1. To define a header for an HTML document
  2. To send raw HTTP headers Correct answer
  3. To include an external PHP file
  4. To set the background color of a webpage

Correct answer

B. To send raw HTTP headers

14 views

MCQSEXAM

Explanation

The header() function sends a raw HTTP header to the browser. Typical uses are redirects (header("Location: /login.php")), setting the content type, and controlling caching.

It must be called before any HTML or whitespace is output, otherwise PHP reports "headers already sent". It has nothing to do with the HTML <header> element.

Want more practice? Try the full set of Computer Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs