使用PHP和CSS的样式切换器
我有这个简单的款式使用PHP和CSS的样式切换器,php,css,Php,Css,我有这个简单的款式 style.css body.defualt { background-color: RGB(230,197,173); background-image:url("img/defualt.gif") ; background-repeat: no-repeat ; font-family : Lucida Handwriting; co
style.css
body.defualt { background-color: RGB(230,197,173);
background-image:url("img/defualt.gif") ;
background-repeat: no-repeat ;
font-family : Lucida Handwriting;
color : white;
}
body.spring {
background-image:url("img/spring.png");
background-repeat: repeat ;
font-family : Arial Rounded MT Bold;
}
body.winter{
background-image:url("img/winter.png");
background-repeat: repeat ;
font-family : Comic Sans MS;
color : RGB(53,31,99);
}
a {text-decoration : none;
color :RGB(175,48,175);
}
a:hover {text-decoration :underline ;
text-transform: uppercase;
}
现在
当我改变了解散的风格,它就改变了
但当刷新时,它会返回到defualt
我想知道如何保存我的风格
<?php
if ($GLOBALS["language"]==arabic)
{include ("ar.php");}
else {include ("en.php");}
?>
<html >
<head>
<title>
MultiMedia
</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="function.js" > </script>
</head>
<body class="defualt">
<br/><br/>
<!-- header -->
<!-- MultiMedia -->
<h1 ><center><?php echo $header ; ?></center></h1>
<!-- theme selector -->
<table style="position:fixed;left:25px;top:210px;" >
<tr> <th> <?php echo $choose?><th> <tr/>
<tr>
<td align=center>
<a onclick ="change('defualt');" title="Defualt" ><img src="img/defualtTHM.gif" style="border-color:white;" border=2 /> </a>
</td>
</tr>
<tr>
<td align=center>
<a onclick ="change('spring');" title="Spring" ><img src="img/springTHM.png" style="border-color:white;" border=2 /> </a>
</td>
</tr>
<tr>
<td align=center>
<a onclick ="change('winter');" title="Winter" ><img src="img/winterTHM.png" style="border-color:white;" border=2 /> </a>
</td>
</tr>
多媒体
您可能希望将语言存储(并设置)为会话变量,而不是全局变量
例如,尝试以下方法:
session_start();
$_SESSION['language'] = "arabic";
然后,您可以更改$_会话,只要调用
SESSION_start(),就可以跨页面跟踪它(仅针对该用户)在尝试访问或更改任何$\u会话
变量之前,请执行code>。将其保留在会话中
如果您使用的是PHP,请将其发送到控制器,然后将值存储在会话中。下次加载PHP文件时,检查会话,如果设置了键,则加载该CSS文件,否则加载默认值
switchstyle.php
$style = isset($_GET['style']) ? $_GET['style'] : false;
if ($style) {
$_SESSION['custom_style'] = $style;
}
在index.php中(假设这是您的视图
if (isset($_SESSION['custom_style'])) {
//load the style
} else {
//load default style
}
注意这只是一个示例/建议。您应该验证您的$\u GET和$\u会话检查,以便保持保护。如果我们可以看到“更改”功能,那就太好了,但我想您需要它
<script type="text/javascript">
function change(theme) {
var date = new Date ();
date.setDate(date.getDate() + 3); // this theme will stay 3 days
document.cookie = 'theme=' + theme + '; expires=' + date.toUTCString()
}
</script>
功能改变(主题){
变量日期=新日期();
date.setDate(date.getDate()+3);//此主题将保留3天
document.cookie='theme='+theme+';expires='+date.toutString()
}
在html中
<body class="<?=isset($_COOKIE['theme'])?$_COOKIE['theme']:'default'?>">
jschange(…)
做什么?if($GLOBALS[“language”]==阿拉伯语)
应该是if($GLOBALS['language']==“阿拉伯语”)
!语言没问题,但我需要让我的新样式保持不变,并且fanction.js发出关于新样式函数更改的通知(theme){document.body.className=theme;警报(theme+“主题是”);}非常感谢