You are here: Re: Cookie problems (simple code included) « PHP Programming Language « IT news, forums, messages
Re: Cookie problems (simple code included)

Posted by ii2o on 09/20/06 14:36

Hi there,

Thanks for the response. Unfortunately even when I move the doctype
statement to below the php code, I still get the following error
"Warning: Cannot modify header information - headers already sent by
(output started at d:\testserver\testcookies.php:3) in
d:\testserver\testcookies.php on line 14".

When you mean before any output is sent to the user, do you mean that I
can't use the $_GET statement? If so, how is possible to select a
stylesheet in the code without accessing this variable?

I'm very confused!

Thanks,
ii2o


Kim André Akerø wrote:
> 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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация