Question
In our full-page refresh example using AJAX, we used a counter in the $_SESSION array to keep track of the number of refreshes. However, we
In our full-page refresh example using AJAX, we used a counter in the $_SESSION array to keep track of the number of refreshes. However, we were really only interested in whether the page had been refreshed or not. Rewrite either or both of these examples to use a boolean array value rather than the counter array value that we did use.
full page refresh:
/*welcome_refresh.php This page displays a welcome message and the complete page is refreshed every 60 seconds. Initially the text color is black, but each refresh uses a randomly chosen text color from red, green, blue or maroon. Because the color choice is random, the same color may repeat after a refresh. */ session_start(); if (!isset($_SESSION['pageRefreshCount'])) $_SESSION['pageRefreshCount']=0; ?>
Welcome Message with Date, Time, and 60-Second Refresh
Welcome!
$greetingColor = "black"; if ($_SESSION['pageRefreshCount'] != 0) { $colorPicker = rand(1, 100); if ($colorPicker > 75) $greetingColor = "red"; else if ($colorPicker > 50) $greetingColor = "green"; else if ($colorPicker > 25) $greetingColor = "blue"; else $greetingColor = "maroon"; } $_SESSION['pageRefreshCount'] = $_SESSION['pageRefreshCount'] + 1; echo "
$greetingColor
"; echo "
It's ".date("l, F jS").". "; echo "The time is ".date("g:ia").".
"; echo "
Or at least that's our time, ". "though it may not be yours.
"; ?>
Pedagogical Note: This page starts off using the default text color of black to display all text. Then the page refreshes every 60 seconds, and each time it does, everything (including this note) is displayed in one of four randomly chosen alternate colors (red, green, blue or maroon) and the date and time are updated.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started