Complete the code to start a session in PHP.
<?php
[1]();
?>In PHP, session_start() is used to begin a session and manage state.
Complete the code to store a user's name in the session.
<?php session_start(); $_SESSION['username'] = [1]; ?>
To store a string value in the session, it must be quoted. So "John" is correct.
Fix the error in the code to correctly check if a session variable exists.
<?php session_start(); if (isset([1]['username'])) { echo "User is logged in."; } ?>
The correct superglobal array for session variables is $_SESSION with uppercase letters.
Fill both blanks to correctly remove a session variable and destroy the session.
<?php session_start(); unset([1]['username']); session_[2](); ?>
Use unset($_SESSION['username']) to remove a session variable and session_destroy() to end the session.
Fill all three blanks to create a session-based counter that increases on each page load.
<?php session_start(); if (!isset([1]['count'])) { [1]['count'] = 1; } else { [1]['count'] [2] [3] 1; } echo "Page views: " . [1]['count']; ?>
Use $_SESSION to store the count. Increment it with += and add 1.
