PHP cookies

Discussion in 'Programming' started by cbisson, Aug 1, 2007.

  1. #1
    Hello,

    trying to use simple cookies here and I'm feeling like a newb lollll

    They just don't want to create lolll, for exemple :

    $time=time()+60480;
    setcookie('lng','en',$time,'/');

    but it doesn't create any .txt cookie file, it simply acts as a session variable, which is not what I want!

    So what am I missing here?

    Chris
     
    cbisson, Aug 1, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Variables are not parsed between single quotes. Just remove the single quotes around $time.
     
    nico_swd, Aug 2, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    He doesn't have any single quotes around the variable...

    cbisson, are you sure the cookie is not being created? Try adding this to your script:
    echo $_COOKIE['lng'];
    PHP:
    Refresh it twice and see if the cookie value shows.
     
    krt, Aug 2, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Lol, I need glasses. :(
     
    nico_swd, Aug 2, 2007 IP
  5. Tarkan

    Tarkan Peon

    Messages:
    491
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Perhaps you couldn't find the cookie file in your browsers cookie folder :/
     
    Tarkan, Aug 2, 2007 IP
  6. cbisson

    cbisson Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok we got it to work

    it seems if you give a too large "expiration" date, it doesn't work!

    although I still don't get much why it didn't work at first with smaller values, we seem to have made it work now lolll


    Thanks for your help

    Chris
     
    cbisson, Aug 3, 2007 IP
  7. neelesh

    neelesh Peon

    Messages:
    141
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It should work logically for watever expiration duration you give it. It is not wise to have a big range for this.
     
    neelesh, Aug 4, 2007 IP
  8. cbisson

    cbisson Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    yeah I agree, but really when we used big big values, it didn't work, and automatically worked when we tried something smaller!!

    life's little mysteries :p


    Chris
     
    cbisson, Aug 6, 2007 IP