Php Cookie only work from 1 page problem! URGENT HELP WEIRD BUG

Discussion in 'PHP' started by Dangy, May 11, 2011.

  1. #1
    The cookie is set here: http://wouldyouratherquestions.net/include/click.php?id=1

    an will also display there on the second reload, but the strange part is wont work on any ny other page on the site. I call the cookie an it's vanished but go back to that page an refresh an still is set anyone know what the problem is?
     
    $id = $_GET['id']; 
     $value = '2';
    setcookie($id,$value, time()+3600*336,'/');
    echo $_COOKIE[$id];
    
    PHP:
    This is the code for the above page.


    This is the code on home page I'm calling the cookie an doesn't work.

     
    $id = $row['id'];
    echo $_COOKIE[$id];
    
    PHP:
    Will not work on any page but that one page above weirdest thing ever.

    Please help tried a lot of solutions.
     
    Dangy, May 11, 2011 IP
  2. JoelLarson

    JoelLarson Peon

    Messages:
    61
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    $domain = '.example.com';
    
    setcookie($id,$value, time()+3600*336,'/', $domain);
    PHP:
    Also use your browser to view cookies and see when they're loaded and if they are removed too quickly.
     
    JoelLarson, May 13, 2011 IP
  3. Dangy

    Dangy Well-Known Member

    Messages:
    841
    Likes Received:
    25
    Best Answers:
    2
    Trophy Points:
    155
    #3
    That wasn't the problem an already tried that too btw. I already fixed it myself anyways.
     
    Dangy, May 14, 2011 IP