In the provided PHP code, what potential pitfalls or errors could lead to the random number changing upon page refresh?
The issue of the random number changing upon page refresh could be due to not using a session to store the random number. To solve this issue, you can store the random number in a session variable so it remains the same across page refreshes.
<?php
session_start();
if (!isset($_SESSION['random_number'])) {
$_SESSION['random_number'] = rand(1, 100);
}
echo "Random number: " . $_SESSION['random_number'];
?>