I want to make a style switcher that changes the style of the page and yet saves the setting so the user comes in next time will see the setting they left with.
Everything seems to be working except for one thing. The problem is that the user needs to select the desired skin twice before it will change to that particular skin. For example, if I want the skin "Red", I click on Red once, nothing happens, but if i click Red again, the skin is changed to red.
Below is my code, please forgive me if my php code is sloppy (inefficient/buggy) as I just started learning this language this week. Please point out any mistakes or things I can improve on so I can learn from this.
<?php
if (isset($skin))
{
switch ($skin)
{
case "2":
$skin = "large.css";
setcookie ('chosenskin', $skin, time()+31536000);
break;
case "3":
$skin = "red.css";
setcookie ('chosenskin', $skin, time()+31536000);
break;
case "4":
$skin = "green.css";
setcookie ('chosenskin', $skin, time()+31536000);
break;
default:
$skin = "regular.css";
setcookie ('chosenskin', $skin, time()+31536000);
break;
}
}
else
{
$skin = "regular.css";
}
$skin = $_COOKIE['chosenskin'];
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo $skin ?>" />
<title></title>
</head>
<body>
<a href="index.php?skin=1">Regular font</a></ br>
<a href="index.php?skin=2">Large font</a></ br>
<a href="index.php?skin=3">Red BG</a></ br>
<a href="index.php?skin=4">Green BG</a></ br>
Test sentence
</body>
</html>
Thank you all in advance.