使用cookie的PHP主题切换器

使用cookie的PHP主题切换器,php,css,cookies,Php,Css,Cookies,我想用一种简单的方法来更新我的网站CSS,以获得更广泛的可访问性 我发现了这个,看起来很有希望: 这是它推荐的PHP代码: index.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Theme Test</title> <link rel="stylesheet" type="text/css" href="<?php echo (

我想用一种简单的方法来更新我的网站CSS,以获得更广泛的可访问性

我发现了这个,看起来很有希望:

这是它推荐的PHP代码:

index.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Theme Test</title>
<link rel="stylesheet" type="text/css" href="<?php echo (!$style)?'normal':$style ?>.css" />
</head>

<body>

 <form action="changestyle.php" method="post">
 <select name="choice">
 <option value="classic" selected>Classic View</option>
 <option value="holiday">Holiday View</option>
 <option value="normal">Normal View</option>
 </select>
 <input type="submit" value="Go">
 </form>

</body>
</html>

主题测试

该教程远非大有可为,除了它对XSS漏洞开放之外,它甚至没有提供完整的工作代码

试试这个尺码

index.php

<link rel="stylesheet" type="text/css" href="<?php echo (!isset($_COOKIE['style'])?'normal':$_COOKIE['style']) ?>.css" />

谢谢你,巴德,是的,这个网站有点差劲。在网站上线之前,我会更详细地了解安全问题,谢谢你的建议。
<link rel="stylesheet" type="text/css" href="<?php echo (!isset($_COOKIE['style'])?'normal':$_COOKIE['style']) ?>.css" />
<?php
$year = 31536000 + time();
setcookie('style', $_POST['choice'], $year);
header('Location: index.php');
exit();