How can sessions be used to securely pass variables between pages in PHP?
Sessions can be used to securely pass variables between pages in PHP by storing the variables in the $_SESSION superglobal array. This array is accessible across different pages as long as the session is active. To pass a variable, you can simply assign a value to a key in the $_SESSION array on one page and retrieve it on another page.
// Start the session
session_start();
// Set a variable in the session
$_SESSION['username'] = 'JohnDoe';
// Retrieve the variable on another page
session_start();
echo $_SESSION['username'];