| Autor | Zpráva | ||
|---|---|---|---|
| naKokos Profil |
#1 · Zasláno: 31. 10. 2011, 23:25:29 · Upravil/a: naKokos
Tak vyřešeno..
<?php
// define styles
$backgrounds = array(
'background1' => 'background-color: #ffe4b5;',
'background2' => 'background-color: #4e4d28;',
'background3' => 'background-color: #a00841;',
);
// make an array of style names
$backgroundNames = array_keys($backgrounds);
// get cookie, default to first style if not found
$backgroundId = isset($_COOKIE['backgroundId']) ? floor($_COOKIE['backgroundId']) : 0;
// prepare background data
$backgroundStyle = array();
$backgroundScript = array();
foreach ($backgrounds as $name => $styles){
$backgroundStyle[] = '#'.$name.' {'.$styles.'}';
$backgroundScript[] = '\''.$name.'\'';
}
?>
<style><?php echo implode(' ', $backgroundStyle); ?></style>
<script>
// Cookie functions from Quirks Mode
// http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
// style changer
var styles = new Array(<?php echo implode(',', $backgroundScript); ?>);
function changeStyle(id){
document.body.id = styles[id];
createCookie('backgroundId', id, 30);
}
</script>
</head>
<body id="<?php echo $backgroundNames[$backgroundId]; ?>">
<ul>
<a href="#" onclick="changeStyle(0)">Defalut</a>
<a href="#" onclick="changeStyle(1)"><img src="http://www.travax.cz/barva/c1.png"></a>
<a href="#" onclick="changeStyle(2)"><img src="http://www.travax.cz/barva/c2.png"></a>
</ul>
</body>
</html> |
||
| naKokos Profil |
#2 · Zasláno: 1. 11. 2011, 00:04:03 · Upravil/a: naKokos
----
|
||
| Rellik Profil |
#3 · Zasláno: 1. 11. 2011, 16:03:24
naKokos:
„----“ a co jako? Jinak nevím proč to děláš tak složitě.. <?php
$css = $_COOKIE['styl'];
$styl = $_POST['css'];
if(!$refer){ $refer = $_SERVER["REQUEST_URI"]; }
if(!$css){ setCookie('styl',"novy.css", time()+36002430,'/'); }
if($styl){ setCookie('styl',$styl, time()+36002430,'/'); //podle potřeby si změňte název cookies. Musí být stejný jako předchozí(styl)
header("Location: $refer");
}
?>
<form action="" method="post">
<input type='radio' name='css' value='novy.css' <?php if($css == "novy.css") echo 'checked="checked" '; ?> > Nový styl <br />
<input type='radio' name='css' value='stary.css' <?php if($css == "stary.css") echo 'checked="checked" '; ?>> Starý styl <br />
<input type="hidden" name="refer" value="<?php echo $refer; ?>">
<input type="submit" name="submit" value=" Použít styl ">
</form> |
||
|
Časová prodleva: 14 let
|
|||
0