SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Mar 2002
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie Value Keeps Disappearing - Cookie Self Deletes

    The code is below. Basically, 2 cookies SHOULD be set when 2 querystrings are used. However, only ONE of them (name) seems to stay put.

    So if I go to my page 'main.php?name=Jim&mainquestion="test" I should
    be able to just go to main.php, without the querystrings, and see values for BOTH cookies.

    But only the cookie for NAME works. I check my browser (firefox) and the cookie for 'mainproblem' just disappears

    Very weird:

    Code:
       $name=$_REQUEST["name"];
       $mainproblem=$_REQUEST["mainquestion"];
       If($name<>"")
       {
       setcookie("name",$name, time()+312536000);
       setcookie("mainproblem",$mainproblem, time()+312536000);
       }
      
       $namecookie=$_COOKIE["name"];
       $prob=$_COOKIE["mainproblem"];
      echo $namecookie; // THIS ONE SHOWS
       echo "<P>$prob"; // THIS ONE IS NOW BLANK/DELETED.

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have error reporting on? You should check that name and mainquestion are set and generate errors if they aren't. My best guess is that there might be a typo somewhere in the form that results in $_RESULT["mainquestion"] not being set.
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  3. #3
    SitePoint Guru
    Join Date
    Mar 2002
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even with one cookie, I can move it to main.php without querystrings, it shows. BUT, if I refresh, it is gone forever

    See below: (and YES, I do have error reporting. This is crazy)

    Code:
     $firstname=$_REQUEST["name"];
     setcookie("firstname",$firstname,time()+3600); 
     
     $first=$_COOKIE["firstname"];
     
     echo $first;

  4. #4
    SitePoint Guru
    Join Date
    Mar 2002
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found a strange solution from an idea I had. Maybe this helps somebody else going through this hell:

    Code:
    If(!isset($_REQUEST["name"]))
    {
    $first=$_COOKIE["firstname"];
    echo $first;
    $option=$_COOKIE["option"];
    echo $option;
    }
    
    If(isset($_REQUEST["name"]))
    {
    $firstname=$_REQUEST["name"];
    setcookie("firstname",$firstname,time()+3600); 
    $option=$_REQUEST["mainproblem"];
    setcookie("option",$option,time()+3600);
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •