What are the best practices for managing session variables in PHP when register_globals is off?
When register_globals is off in PHP, session variables should be managed using the $_SESSION superglobal array. This array allows you to store and retrieve session variables securely without relying on global variables. To set a session variable, use $_SESSION['variable_name'] = 'value'; and to retrieve it, use $variable = $_SESSION['variable_name']; Remember to start the session with session_start() at the beginning of your script.
<?php
session_start();
// Set a session variable
$_SESSION['username'] = 'john_doe';
// Retrieve the session variable
$username = $_SESSION['username'];
echo $username; // Output: john_doe
?>