I am currently trying to get a style switcher to work based off of a script I found on this website.
When I test the site locally, and I click the links to change the style, the page goes blank. Just to see what would happen I uploaded the page to my site. When tested live the site still would not load the style, but the screen does not go blank when the links are clicked. Instead, it only flickers.
Here is the markup:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
// Checks for, and assigns cookie to local variable:
if(!empty($_COOKIE['style'])) $style = $_COOKIE['style'];
// If no cookie is present then set style as "day" (default):
else $style = 'day';
?>
<link id="stylesheet" type="text/css" href="css/<?php echo $style ?>.css" rel="stylesheet"/>
</head>
<body>
<div id="container">
<div id="Main">
<h1>Title</h1>
<div id="links">
<ul>
<li>link1</li>
<li> link2</li>
<li> link3</li>
</ul>
</div>
<div class="seperator1"></div>
<div class="portfolioItem">
<p class="portfolioDesc">A description of a website</p>
<p class="portfolioImg">Web Site Image</p>
</div>
<div class="seperator2"></div>
<div class="portfolioItem">
<p class="portfolioDesc">A description of a website</p>
<p class="portfolioImg">Web Site Image</p>
</div>
<div id="style-switcher">
<p>change theme</p>
<h4>Choose your style:</h4>
<ul>
<li id="day"><a href="style-switcher.php?style=day">Day</a></li>
<li id="night"><a href="style-switcher.php?style=night">Night</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
Here is the code which sets the style:
<?php
$style = $_GET['style'];
setcookie("style", $style, time()+604800); // 604800 = amount of seconds in one week
if(isset($_GET['js'])) {
echo $style;
} else {
header("Location: ".$_SERVER['HTTP_REFERER']);
}
?>
It may only be a simple fix I know, but I've only recently started working with php, and I cannot identify some parts of the code. I've checked to be sure names of stylesheets and variables are consistent, but that certainly means I didn't overlook anything.