Setting Cookies

Discussion in 'PHP' started by Dolin, Jan 1, 2008.

  1. #1
    Hi everytime I reload my browser it said my cookie is not set. Is my code wrong?

    setcookie('youngcounter', 'dolinred', time() + 36000, '/', '.young.3host.biz');
     
    Dolin, Jan 1, 2008 IP
  2. WeedGrinch

    WeedGrinch Active Member

    Messages:
    1,236
    Likes Received:
    73
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Try this:
    setcookie('youngcounter', 'dolinred', time() + 36000, '/', 'young.3host.biz');

    I made one simple change.
     
    WeedGrinch, Jan 1, 2008 IP
  3. Dolin

    Dolin Banned

    Messages:
    143
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It sitll doesn't work. Cookies are still not set.

    if (!isset($_COOKIE['youngcounter']))
    {

    setcookie('youngcounter', 'dolin', time() + 36000, '/', 'young.3host.biz');

    }

    Is there anything wrong with the code?
     
    Dolin, Jan 1, 2008 IP
  4. WeedGrinch

    WeedGrinch Active Member

    Messages:
    1,236
    Likes Received:
    73
    Best Answers:
    0
    Trophy Points:
    90
    #4
    setcookie('youngcounter', 'dolin', time() + 36000)

    Use that
     
    WeedGrinch, Jan 1, 2008 IP
  5. Dolin

    Dolin Banned

    Messages:
    143
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nope doesn't work still. Is it a problem with my host or my codes? I tried the codes in my localhost and the cookie is set, but I tried it on my website the cookie is not set.
     
    Dolin, Jan 1, 2008 IP
  6. WeedGrinch

    WeedGrinch Active Member

    Messages:
    1,236
    Likes Received:
    73
    Best Answers:
    0
    Trophy Points:
    90
    #6
    I think its your host, because it should work.
    BTW you should use sessions!
     
    WeedGrinch, Jan 1, 2008 IP
  7. Ziaja

    Ziaja Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Before you use cookies, you need ob_start() at the very start of your script.
     
    Ziaja, Jan 1, 2008 IP
  8. Dolin

    Dolin Banned

    Messages:
    143
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Are you sure Ziaja? My cookies work fine in my local server. I was thinking there is a functional limit at my host. Anyway I am willing to hear about the obj_start() function if it can set up my cookie in my website.
     
    Dolin, Jan 1, 2008 IP
  9. lslars31

    lslars31 Peon

    Messages:
    260
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0