SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast cwb's Avatar
    Join Date
    May 2004
    Location
    Michigan
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie Value Not Updating

    I am trying set a cookie on my site for an id. The cookie sets fine but I want the cookie to update if the value of the cookie changes. I am using the code below but it is not updating the value of the cookie when it changes.

    I have this code on the top of every page on the site:

    PHP Code:
    if (isset($_COOKIE['id'])) {
      if (
    $_COOKIE['id'] != $idsetcookie("id"$idtime()+3600);
    } else {
      
    setcookie("id"$idtime()+3600"/"".mydomain.com"0);

    Thanks for any help

  2. #2
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, try this:

    PHP Code:
    if (isset($_COOKIE['id'))
    {
        if (
    $_COOKIE['id'] != $id)
        {
            
    setcookie("id"$idtime()+3600);
        }
    }
    else
    {
        
    setcookie("id"$idtime()+3600);

    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  3. #3
    SitePoint Enthusiast cwb's Avatar
    Join Date
    May 2004
    Location
    Michigan
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code is giving me all kinds of errors... I try to fix one but then get another.
    Thanks for trying though

  4. #4
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, my bad... stupid parse errors

    PHP Code:
    if (isset($_COOKIE['id']))
    {
        if (
    $_COOKIE['id'] != $id)
        {
            
    setcookie("id"$idtime()+3600);
        }
    }
    else
    {
        
    setcookie("id"$idtime()+3600);

    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  5. #5
    SitePoint Enthusiast cwb's Avatar
    Join Date
    May 2004
    Location
    Michigan
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, got the code fixed.. but still didn't work

  6. #6
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We'll need to see some code... I just tested that snippet of coding in a web browser and it works fine.
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  7. #7
    SitePoint Enthusiast cwb's Avatar
    Join Date
    May 2004
    Location
    Michigan
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used the code you gave me.. not sure what else could I give?
    Maybe it is a problem with my browser. Got an old computer.
    I'll have some friends test.

    Thanks for the help.

  8. #8
    SitePoint Enthusiast cwb's Avatar
    Join Date
    May 2004
    Location
    Michigan
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Having the code on the top of every page wouldn't hurt things would it?

  9. #9
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any session or cookie functions such as setcookie and session_start MUST be put at the TOP of the page otherwise you'll get parse error such as "Headers already sent!"
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs


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
  •