|
Posted by Kim Andrι Akerψ on 09/20/06 14:32
ii2o wrote:
> 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 <html> tag, 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("***$cstyle***");
>
> if ($cstyle < 1 || $cstyle > 3)
> {
> $cstyle = 1;
> }
>
> @extract($_POST);
> $cstylenew = (int)$_GET['cstyle'];
>
> if ($cstylenew >= 1 && $cstylenew <= 3)
> {
> setcookie("cstyle3", "$cstylenew", time()+5000000);
> }
> ?>
>
> <html>
>
> <head>
> <link href="style<?php print($cstyle);?>.css" rel="stylesheet"
> type="text/css">
> </head>
>
> <body>
> <br>
> <a href="<?php print("$PHP_SELF"); ?>?cstyle=1">style 1</a><br>
> <a href="<?php print("$PHP_SELF"); ?>?cstyle=2">style 2</a><br>
> <a href="<?php print("$PHP_SELF"); ?>?cstyle=3">style 3</a><br>
> </body>
> </html>
>
> Best regards,
> ii2o
Cookies are set in the headers, meaning that setcookie() must be called
before *any* output is sent to the user (even before your DOCTYPE
statement). Make sure that you don't have any blank spaces before <?php
as well.
--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Navigation:
[Reply to this message]
|