Jump to content

Cookie problem - Code worked on one server, but not on another


magicmoose

Recommended Posts

Hi, I have a piece of code which I want to use to allow the user to select a stylesheet.  I had it working fine on another site, but I have just added the same code to a new site I am making and it's not working.

 

At the top of my 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); // update or create the cookie

?>

 

In the head tags I have this:

 

<LINK REL="stylesheet" HREF="stylesheet<?= $style; ?>.css">

 

And in the body of the page I have the following 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>

 

Can anyone see any problems with it?

If not, what settings do I need to get changed?

I can post the settings from the php.php files if needed.

 

Thanks.

Link to comment
Share on other sites

Didn't know that, thanks. 

I forgot to mention, after the form is submitted, the stylesheet DOES change, but only for one page.  It goes back to the default value afterwards, whether I load up a different page, or the same one again.

I am having a similar problem with sessions, it just seems that nothing will pass from one page to another.

I have tried just putting a random value in both a cookie and session variable and echoing it on another page, but nothing is displayed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.