0
0
PHPprogramming~10 mins

Destroying sessions in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a session in PHP.

PHP
<?php
session_[1]();
?>
Drag options to blanks, or click blank then click option'
Abegin
Bopen
Cinit
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using session_open() or session_init() which do not exist.
Forgetting to start the session before using session variables.
2fill in blank
medium

Complete the code to unset a specific session variable named 'user'.

PHP
<?php
unset($_SESSION[1]);
?>
Drag options to blanks, or click blank then click option'
A{'user'}
B('user')
C['user']
D<'user'>
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or curly braces instead of square brackets.
Not quoting the session variable name.
3fill in blank
hard

Fix the error in the code to destroy the session properly.

PHP
<?php
session_start();
session_[1]();
?>
Drag options to blanks, or click blank then click option'
Astop
Bdestroy
Cend
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using session_stop() or session_end() which do not exist.
Calling session_destroy() without starting the session first.
4fill in blank
hard

Fill both blanks to unset all session variables and then destroy the session.

PHP
<?php
session_start();
[1] = array();
session_[2]();
?>
Drag options to blanks, or click blank then click option'
A$_SESSION
Bsession_destroy
Csession_destroy()
D$session
Attempts:
3 left
💡 Hint
Common Mistakes
Using $session instead of $_SESSION.
Putting parentheses in the blank for session_destroy causing syntax errors.
5fill in blank
hard

Fill all three blanks to properly destroy a session and delete the session cookie.

PHP
<?php
session_start();
$_SESSION = array();
if (ini_get('session.use_cookies')) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - [1], $params[2], $params[3], true, true);
}
session_destroy();
?>
Drag options to blanks, or click blank then click option'
A3600
B['path']
C['domain']
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using a positive number for expiration time which does not delete the cookie.
Forgetting to use the correct keys 'path' and 'domain' from $params.