PHP - Cookies not setting

Associate
Joined
25 Jul 2005
Posts
430
Hi. I've tried to copy something I had in an old site to a new one I'm making. It's a simple stylesheet selector and it worked fine on the old site.
After finding out it didn't work, I tried assigned some cookie variables and tried to echo them in another page, just to test it and that didn't work either.
I guess I need to change some of the server settings, but I don't know php well enough to know what to ask for :p
Any idea which things need changing?
I can post the contents of the php.php file if needed.
Thx.
 
OK. At the top of the page I have:
<?


if (isset($_COOKIE["selectedStyle"])) // has the cookie already been set
{
$style=$_COOKIE["selectedStyle"];
}else{
$style = 0;
}

if (isset($_POST["changeStyle"])) // changing the style
{
$style=$_POST["changeStyle"];
}

setcookie("selectedStyle",$style, time()+36000, "/"); // update or create the cookie
?>

Then within the head tags I have this:
<LINK REL="stylesheet" HREF="stylesheet<?php echo $style; ?>.css">

And finally the form:
<form method="post" action="<?= $_SERVER["PHP_SELF"];?>">
<P class="general">Normal<input type="radio" name="changeStyle" value="0" checked><BR></P>
<P class="general">Text Only (No Flash Content)<input type="radio" name="changeStyle" value="1"><BR></P>

<INPUT type="submit" name="submitstyle" value="Change"><BR>
</form>

Every other page simply has the following at the top (as well as the head section):
<?
if (isset($_COOKIE["selectedStyle"])) // if style has been set, use selected style
{
$style=$_COOKIE["selectedStyle"];
}
else // if style not yet set, default to 0
{
$style=0;
}
?>

When it reloads the page immediately after using the form, it works (but no cookies are used to achieve this), however, as soon as I load another page (or even the same one) it goes back to the default value.

EDIT - Just checked register globals is on for both sites. :confused:
 
Last edited:
Back
Top Bottom