I have got a working PHP of a theme change with a cookie attached that remembers the theme color when the user leaves the site. But I need to change this to javascript instead and still draws on the CSS file. How do I do this?
This is the php file I have
<html>
<head>
<?php
//GET method to retrieve the theme for the user
if (isset($_GET["theme"])) {
if ($_GET["theme"] == 'blue') {
// set theme to be blue by default unless the user has selected red or
yellow theme then change
// once user has selected theme browser will remember for 1 year
setcookie("theme", "blue", strtotime('+1 year'));
} else if ($_GET["theme"] == 'red') {
setcookie("theme", "red", strtotime('+1 year'));
} else if ($_GET["theme"] == 'yellow') {
setcookie("theme", "yellow", strtotime('+1 year'));
}
header("Location: index.php");
}
/* once user logs out. session is to rememebr the color chosen as above,
logging out to location index.php */
if (isset($_GET["logout"]) && $_GET["logout"] == 'true') {
session_destroy();
header("Location: index.php");
die;
}
// use theme cookie
if (isset($_COOKIE["theme"])) {
if ($_COOKIE["theme"] == "yellow") {
/* if yellow theme is selected use stylesheet yellow
otherwise if not select */
red style sheet
echo '<link rel="stylesheet" type="text/css" href="styles/styleyellow.css">';
} else if ($_COOKIE["theme"] == "red") {
echo '<link rel="stylesheet" type="text/css" href="styles/stylered.css">';
} else {
/* if yellow or red were not selected
then set to default blue stylesheet theme */
echo '<link rel="stylesheet" type="text/css" href="styles/styleblue.css">';
}
} else {
echo '<link rel="stylesheet" type="text/css" href="styles/styleblue.css">';
}
?>
</head>
<body>
<?php
/* once the user has logged in
this shows options for the user to change theme colors. */
if (isset($_SESSION["username"])) {
echo '<div id="theme">';
echo 'Set a Theme:<br>';
echo '<a href="index.php?theme=blue">Blue (Default)</a><br>';
echo '<a href="index.php?theme=red">Red</a><br>';
echo '<a href="index.php?theme=yellow">Yellow</a><br>';
echo '</div>';
}
?>
</body>
</html>