I have an html table which I want to have a night mode and a day mode. I've built a very basic example of what I'm trying to do below. The boxes in this table will have different colors depending on whether their class is set to "condition_night" or "condition_day". The page will refresh quite often so I'm trying to use the php SESSION object to keep the mode of the page across refreshes. See snippet
<?php
session_start();
if(isset($_SESSION['MODE']) && $_SESSION['MODE'] === 'night'){
$mode = 'night';
} else {
$mode = 'day';
};
?>
<style>
.condition_night {
background-color: grey;
color: black;
}
.condition_day {
background-color: blue;
color: white;
}
</style>
<table>
<thead>
<tr>
<th class="condition_<?=$mode;?>">Person</th>
<th class="condition_<?=$mode;?>">Score</th>
</tr>
</thead>
<tbody>
<tr>
<td>James</td>
<td>100%</td>
</tr>
</tbody>
</table>
<input type="button" name="night_mode" class="btn btn-secondary" value="Night Mode" onclick="change_session_day.php;" data-dismiss="modal" style="width: 170px;margin-top: 5px;margin-bottom: 5px;"/>
<input type="button" name="day_mode" class="btn btn-secondary" value="Day Mode" onclick="change_session_day.php;" data-dismiss="modal" style="width: 170px;margin-top: 5px;margin-bottom: 5px;"/>
I am fully aware that the buttons at the bottom of the page won't work I've put them there as an example of what I'm trying to achieve. Is there a way to make the buttons call a separate php script on another page which will change the SESSION['MODE'} variable, then refresh the page so that the new colors are apparent?
The script on the php page would go along the lines of See Snippet
<?php
session_start();
$_SESSION['MODE']="day";
//Refresh page here
?>