How can sessions be used in PHP to maintain variables across multiple script executions?
Sessions in PHP can be used to maintain variables across multiple script executions by storing the variables in a session array that persists between page loads. To start a session, you can use the session_start() function at the beginning of your script. Then, you can set variables in the $_SESSION superglobal array to store data that needs to be maintained across multiple script executions.
<?php
// Start the session
session_start();
// Set a session variable
$_SESSION['username'] = 'JohnDoe';
// Access the session variable in another script execution
echo $_SESSION['username'];
?>