How can session IDs be used to make variables persistent across multiple pages in PHP?
Session IDs can be used in PHP to make variables persistent across multiple pages by storing them in the $_SESSION superglobal array. This array is accessible across different pages as long as the session remains active. To start a session and set variables, you can use session_start() at the beginning of each page and then assign values to $_SESSION['variable_name']. This allows you to maintain data between different pages for a specific user session.
<?php
// Start the session
session_start();
// Set a session variable
$_SESSION['username'] = 'JohnDoe';
// Access the session variable on another page
session_start();
echo $_SESSION['username']; // Output: JohnDoe
?>