Reply to Cookie problems (simple code included)

Your name:

Reply:


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

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

[Back to original 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

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