Switch Site Colour Themes

I have a value in my database that is queried on all pages of my dynamic 1 page website (if that makes sense), the data has one of 3 possibilities which change the colour theme of my website.

The 3 possible values are BLUE | GREEN | BOTH

There are some pages that must show the BLUE theme, others that must show the GREEN theme and others where it does not matter which it displays, preferably if the user was just viewing a bunch of GREEN pages and then navigates to a BOTH page then I would like the theme to remain GREEN as per whatever they were viewing last.

On a static website
With normal PHP i would have done something like this on a BLUE page

<?php 
    session_start();
    $_SESSION['themeSwitching']='BLUE';
?>

And a GREEN page

<?php 
    session_start();
    $_SESSION['themeSwitching']='GREEN';
?>

And for a BOTH page I would need to do a check first and if it is already set to BLUE or GREEN do nothing otherwise set it to a default of whichever, in my case GREEN

<?php 
    session_start();
    if(!isset($_SESSION['themeSwitching'])) { $_SESSION['themeSwitching']='GREEN'; }
?>

How would I replicate this sort of functionality within my new dynamic one page website, and should I consider using datastore or stick with sessions?

Community Page
Last updated: