Complete the code to start a session in PHP.
<?php
[1];
?>In PHP, session_start() is used to start a new session or resume an existing one.
Complete the code to set a session variable named 'user' with value 'Alice'.
<?php session_start(); $_SESSION[[1]] = 'Alice'; ?>
The session variable key should be 'user' to match the requirement.
Fix the error in the code to correctly start a session and set a variable.
<?php [1]; $_SESSION['count'] = 1; ?>
The correct function to start a session is session_start(). Other options are invalid.
Fill both blanks to check if a session variable 'logged_in' is set and true.
<?php session_start(); if (isset($_SESSION[1]) && $_SESSION[2] === true) { echo 'User is logged in'; } ?>
To check the session variable 'logged_in', use ['logged_in'] in both places.
Fill all three blanks to start a session, set 'role' to 'admin', and then print it.
<?php [1]; $_SESSION[2] = 'admin'; echo $_SESSION[3]; ?>
Start the session with session_start(), then use the key 'role' in square brackets to set and print the session variable.