0
0
PHPprogramming~5 mins

Destroying sessions in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of session_destroy() in PHP?

session_destroy() ends the current session and deletes all data associated with it on the server.

Click to reveal answer
beginner
Which PHP function removes all session variables but does not destroy the session itself?

session_unset() clears all session variables but keeps the session active.

Click to reveal answer
beginner
Why should you call session_start() before destroying a session?

You must call session_start() to access the current session before you can destroy it.

Click to reveal answer
intermediate
How do you delete the session cookie in PHP when destroying a session?

Use setcookie() with the session cookie name, an empty value, and a past expiration time.

Click to reveal answer
intermediate
What is the correct order to fully destroy a PHP session?
  1. Call session_start()
  2. Clear session variables with $_SESSION = [] or session_unset()
  3. Delete the session cookie with setcookie()
  4. Call session_destroy()
Click to reveal answer
What does session_destroy() do in PHP?
AClears session variables but keeps session active
BDeletes all session data on the server
CStarts a new session
DDeletes the session cookie only
Which function clears all session variables but does not destroy the session?
Asession_unset()
Bsession_destroy()
Csession_start()
Dsession_regenerate_id()
Before calling session_destroy(), what must you do?
ACall <code>session_start()</code>
BCall <code>session_unset()</code>
CDelete the session cookie
DNothing, just call <code>session_destroy()</code>
How do you delete the session cookie in PHP?
ACall <code>session_destroy()</code>
BCall <code>session_start()</code>
CSet cookie with empty value and past expiration time
DCall <code>session_unset()</code>
What is the correct sequence to fully destroy a PHP session?
Asession_unset() → session_destroy() → session_start()
Bsession_destroy() → session_start() → delete cookie
Cdelete cookie → session_destroy() → session_start()
Dsession_start() → session_unset() → delete cookie → session_destroy()
Explain the steps needed to completely destroy a PHP session and why each step is important.
Think about both server data and client cookie.
You got /4 concepts.
    What is the difference between session_unset() and session_destroy() in PHP?
    One clears variables, the other ends the session.
    You got /4 concepts.