Something like this should work.
Put this in the <head> section of your web page - the last line echos out a stylesheet so put it where you'd want that to appear;
PHP Code:
<?php
$default = 'styles.css'; // define stylesheets
$darkcss = 'dark.css';
$lightcss = 'light.css';
$expire = time()+60*60*24*30; // how long to remember css choice (60*60*24*30 = 30 days)
if ( (isset($_GET['css'])) && ($_GET['css'] == $lightcss) ) { // set cookie for light css
$_SESSION['css'] = $_GET['css'];
setcookie('css', $_GET['css'], $expire);
}
if ( (isset($_GET['css'])) && ($_GET['css'] == $darkcss) ) { // set cookie for dark css
$_SESSION['css'] = $_GET['css'];
setcookie('css', $_GET['css'], $expire);
}
if ( (isset($_GET['css'])) && ($_GET['css'] == $default) ) { // set cookie for default css
$_SESSION['css'] = $_GET['css'];
setcookie('css', $_GET['css'], $expire);
}
if (isset($_COOKIE['css'])) { // check for css stored in cookie
$savedcss = $_COOKIE['css'];
} else {
$savedcss = $default;
}
if ($_SESSION['css']) { // use session css else use cookie css
$css = $_SESSION['css'];
} else {
$css = $savedcss;
}
// the filename of the stylesheet is now stored in $css
echo '<link rel="stylesheet" href="/path/to/styles/'.$css.'">';
?>
The filename of the stylesheet is stored in the $css variable so you can use this to insert style-specific content;
PHP Code:
<?php if ($css == 'styles.css') { ?>
<p>DEFAULT CONTENT</p>
<?php } ?>
<?php if ($css == 'dark.css') { ?>
<p>DARK CONTENT</p>
<?php } ?>
<?php if ($css == 'light.css') { ?>
<p>LIGHT CONTENT</p>
<?php } ?>
And these would be the links to switch / change stylesheets;
PHP Code:
<a href="?css=<?php echo $lightcss;?>">Light</a>
<a href="?css=<?php echo $darkcss;?>">Dark</a>
<a href="?css=<?php echo $default;?>">Default</a>
Bookmarks