PHP实现页面样式切换
写给自己备忘的...
changStyle.php:
1 $color = $_GET["color"];
2 setcookie('color',$color,time()+31536000);
3 header("location:".$_SERVER['HTTP_REFERER']);
2 setcookie('color',$color,time()+31536000);
3 header("location:".$_SERVER['HTTP_REFERER']);
index.php:
1 <?php
2 if(isset($_COOKIE['color'])){
3 $color = $_COOKIE['color'];
4 //通过选择得到的当前样式
5 $style = "../webdoc/css/service/".$color."/style.css";
6 }else{
7 //页面加载后默认的样式
8 $style = "../webdoc/css/service/blue/style.css";
9 }
10 ?>
2 if(isset($_COOKIE['color'])){
3 $color = $_COOKIE['color'];
4 //通过选择得到的当前样式
5 $style = "../webdoc/css/service/".$color."/style.css";
6 }else{
7 //页面加载后默认的样式
8 $style = "../webdoc/css/service/blue/style.css";
9 }
10 ?>
index.php中的head部分:
1 <link rel="stylesheet" type="text/css" href="<?php echo $style ?>" />
index.php中的html部分:
1 <a href="changeStyle.php?color=blue">蓝色</a>
2 <a href="changeStyle.php?color=gray">灰色</a>
3 <a href="changeStyle.php?color=red">红色</a>
4 <a href="changeStyle.php?color=green">绿色</a>
2 <a href="changeStyle.php?color=gray">灰色</a>
3 <a href="changeStyle.php?color=red">红色</a>
4 <a href="changeStyle.php?color=green">绿色</a>
OK,搞定,收工!