What are common methods for passing variables between pages in PHP?
When passing variables between pages in PHP, common methods include using sessions, GET or POST parameters, cookies, or using hidden form fields.
// Using sessions
session_start();
$_SESSION['variable_name'] = $value;
// Using GET parameters
<a href="page2.php?variable_name=<?php echo $value; ?>">Go to Page 2</a>
// Using POST parameters
<form action="page2.php" method="post">
<input type="hidden" name="variable_name" value="<?php echo $value; ?>">
<button type="submit">Submit</button>
</form>
// Using cookies
setcookie("variable_name", $value, time() + 3600, "/");
// Using hidden form fields
<form action="page2.php" method="post">
<input type="hidden" name="variable_name" value="<?php echo $value; ?>">
<button type="submit">Submit</button>
</form>