Bird
0
0

Which of the following PHP code snippets correctly starts a session to preserve data across requests?

easy📝 Syntax Q12 of 15
PHP - Request Lifecycle
Which of the following PHP code snippets correctly starts a session to preserve data across requests?
A<?php session_start(); $_SESSION['count'] = 1; ?>
B<?php start_session(); $_SESSION['count'] = 1; ?>
C<?php session_begin(); $_SESSION['count'] = 1; ?>
D<?php session(); $_SESSION['count'] = 1; ?>
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct PHP function to start a session

    The correct function is session_start() to begin or resume a session.
  2. Step 2: Check the code syntax

    uses session_start() correctly; others use invalid function names.
  3. Final Answer:

    <?php session_start(); $_SESSION['count'] = 1; ?> -> Option A
  4. Quick Check:

    Use session_start() to begin sessions [OK]
Quick Trick: Use session_start() exactly to enable sessions [OK]
Common Mistakes:
  • Using incorrect function names like start_session()
  • Forgetting to call session_start() before using $_SESSION
  • Assuming sessions start automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes