Bird
0
0

Find the error in this PHP session code:

medium📝 Debug Q7 of 15
PHP - Sessions and Cookies
Find the error in this PHP session code:
<?php
session_start();
$_SESSION['name'] = 'Eve';
session_destroy();
echo $_SESSION['name'];
?>
Aecho statement syntax is invalid
Bsession_destroy() deletes session but $_SESSION still accessible
C$_SESSION cannot store strings
Dsession_start() is called after session_destroy()
Step-by-Step Solution
Solution:
  1. Step 1: Understand session_destroy() effect

    Calling session_destroy() deletes session data on the server but does not unset the $_SESSION array in the current script.
  2. Step 2: Analyze echo behavior

    After destroying the session, $_SESSION['name'] still exists in memory and will be echoed.
  3. Final Answer:

    session_destroy() deletes session but $_SESSION still accessible -> Option B
  4. Quick Check:

    session_destroy() clears session but $_SESSION remains until script ends [OK]
Quick Trick: Unset $_SESSION variables after session_destroy() to clear data [OK]
Common Mistakes:
  • Expecting session_destroy() to clear $_SESSION immediately
  • Calling session_start() after session_destroy()
  • Confusing session_destroy() with unset($_SESSION)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes