Hi all,
I'm trying to develop a website that selects from 3 stylesheets
depending on which style they have chosen. Their preference is stored
in a cookie and this is where the problems begin. I have boiled my code
down to the bare essentials in the hope that someone can help me with
this problem. I would be grateful if you could explain what I have done
is wrong too, because I read that cookie settings should be done before
the <htmltag, which is what I have done.
=== CODE (this can be copied and pasted into a php file) ===
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<?php
$cstyle = (int)$_COOKIE["cstyle"];
print("***$csty le***");
if ($cstyle < 1 || $cstyle 3)
{
$cstyle = 1;
}
@extract($_POST );
$cstylenew = (int)$_GET['cstyle'];
if ($cstylenew >= 1 && $cstylenew <= 3)
{
setcookie("csty le3", "$cstylenew ", time()+5000000) ;
}
?>
<html>
<head>
<link href="style<?ph p print($cstyle); ?>.css" rel="stylesheet "
type="text/css">
</head>
<body>
<br>
<a href="<?php print("$PHP_SEL F"); ?>?cstyle=1">st yle 1</a><br>
<a href="<?php print("$PHP_SEL F"); ?>?cstyle=2">st yle 2</a><br>
<a href="<?php print("$PHP_SEL F"); ?>?cstyle=3">st yle 3</a><br>
</body>
</html>
Best regards,
ii2o
I'm trying to develop a website that selects from 3 stylesheets
depending on which style they have chosen. Their preference is stored
in a cookie and this is where the problems begin. I have boiled my code
down to the bare essentials in the hope that someone can help me with
this problem. I would be grateful if you could explain what I have done
is wrong too, because I read that cookie settings should be done before
the <htmltag, which is what I have done.
=== CODE (this can be copied and pasted into a php file) ===
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<?php
$cstyle = (int)$_COOKIE["cstyle"];
print("***$csty le***");
if ($cstyle < 1 || $cstyle 3)
{
$cstyle = 1;
}
@extract($_POST );
$cstylenew = (int)$_GET['cstyle'];
if ($cstylenew >= 1 && $cstylenew <= 3)
{
setcookie("csty le3", "$cstylenew ", time()+5000000) ;
}
?>
<html>
<head>
<link href="style<?ph p print($cstyle); ?>.css" rel="stylesheet "
type="text/css">
</head>
<body>
<br>
<a href="<?php print("$PHP_SEL F"); ?>?cstyle=1">st yle 1</a><br>
<a href="<?php print("$PHP_SEL F"); ?>?cstyle=2">st yle 2</a><br>
<a href="<?php print("$PHP_SEL F"); ?>?cstyle=3">st yle 3</a><br>
</body>
</html>
Best regards,
ii2o
Comment