Complete the code to start a session in PHP.
<?php
[1];
?>In PHP, session_start() is used to start a session or resume the current one.
Complete the code to set a session variable named 'user' with value 'Alice'.
<?php session_start(); $_SESSION[[1]] = 'Alice'; ?>
Session keys must be strings, so use quotes around 'user'.
Fix the error in the code to correctly retrieve the session variable 'user'.
<?php session_start(); $username = $_SESSION[1]user[2]; echo $username; ?>
Session variables are accessed using square brackets and quotes around the key.
Fill both blanks to check if a session variable 'loggedIn' is set and true.
<?php session_start(); if (isset($_SESSION[1]loggedIn[2]) && $_SESSION['loggedIn'] === true) { echo 'Welcome!'; } ?>
Use square brackets with quotes to check if the session variable exists.
Fill all three blanks to unset the session variable 'cart', destroy the session, and redirect to 'index.php'.
<?php session_start(); unset($_SESSION[1]cart[2]); session[3](); header('Location: index.php'); exit(); ?>
session_close() instead of session_destroy().To remove a session variable, use unset($_SESSION['cart']). To end the session, use session_destroy().