Bird
0
0

Why is it important to call session_start() before any HTML output in PHP?

hard📝 Conceptual Q10 of 15
PHP - Sessions and Cookies
Why is it important to call session_start() before any HTML output in PHP?
ABecause session_start() caches the HTML output.
BBecause session_start() generates HTML content.
CBecause session_start() encrypts the page content.
DBecause session_start() sends HTTP headers which must be sent before output.
Step-by-Step Solution
Solution:
  1. Step 1: Understand HTTP headers and output order

    PHP sessions use cookies sent via HTTP headers, which must be sent before any HTML output.
  2. Step 2: Analyze other options

    Session_start() does not generate HTML, encrypt content, or cache output.
  3. Final Answer:

    Because session_start() sends HTTP headers which must be sent before output. -> Option D
  4. Quick Check:

    session_start() must run before output to send headers [OK]
Quick Trick: Call session_start() before any echo or HTML output [OK]
Common Mistakes:
  • Calling session_start() after HTML causes header errors
  • Thinking session_start() outputs HTML
  • Ignoring header rules in PHP

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes