How can PHP be used to pass variables after a new page is reloaded?

When a new page is reloaded, PHP can pass variables through the use of sessions or cookies. Sessions store variables on the server side, while cookies store variables on the client side. By setting session variables or cookie values before the page reloads, the variables can be accessed on the new page.

// Set a session variable before the page reloads
session_start();
$_SESSION['variable_name'] = 'value';

// Redirect to the new page
header('Location: new_page.php');
exit;

// On the new_page.php, access the session variable
session_start();
$passed_variable = $_SESSION['variable_name'];
echo $passed_variable;