Complete the code to start a session in PHP.
<?php
[1]();
?>In PHP, session_start() is used to begin a session so variables can persist across requests.
Complete the code to store a value in a session variable.
<?php session_start(); $_SESSION[[1]] = 'blue'; ?>
Session keys must be strings, so use quotes like 'color' to store the value.
Fix the error in the code to access a session variable.
<?php
session_start();
echo $_SESSION[1];
?>To access a session variable, use square brackets with the key as a string: $_SESSION['color'].
Fill both blanks to check if a session variable exists and then print it.
<?php session_start(); if (isset($_SESSION[1])) { echo $_SESSION[2]; } ?>
Use the same session key inside isset() and when echoing the value to check and print it correctly.
Fill all three blanks to correctly start a session, set a variable, and then print it.
<?php [1](); $_SESSION[2] = 'admin'; echo $_SESSION[3]; ?>
First, start the session with session_start(). Then set and access the session variable using the same key ['role'].