SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru SharifTK's Avatar
    Join Date
    Jan 2004
    Location
    New York, NY
    Posts
    621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie value not updating...

    Say I run setcookie('sid', session_id(), time()+604800, '/', 'mydomain.com'), and then close browser, then i open browser again and run that code again, wouldn't it replace the value of sid?
    SK

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Normally it would, as you have given up an expiration timestamp and that isn't expired that fast...

  3. #3
    SitePoint Guru SharifTK's Avatar
    Join Date
    Jan 2004
    Location
    New York, NY
    Posts
    621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well it isn't updating, any ideas why ?
    SK

  4. #4
    SitePoint Guru SharifTK's Avatar
    Join Date
    Jan 2004
    Location
    New York, NY
    Posts
    621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the code that is not working:

    PHP Code:
    $sql "UPDATE ";
    $sql.= "sessions ";
    $sql.= "SET ";
    $sql.= "sid = '" session_id() . "', time = now() ";
    $sql.= "WHERE ";
    $sql.= "sid = '" $_COOKIE['sid'] . "'";
    $query mysql_query($sql);
                            
    setcookie('sid'$sidtime()+604800'/''onlyonxbox.net');
                            
    unset(
    $sql);
    unset(
    $query);
                            
    $sql "SELECT ";
    $sql.= "DATE_FORMAT(time, '%m/%d/%Y at %l:%i:%s %p') AS timestamp ";
    $sql.= "FROM ";
    $sql.= "sessions ";
    $sql.= "WHERE ";
    $sql.= "sid = '" $_COOKIE['sid'] . "'";
    $query mysql_query($sql); 
    There is a lot of other code in this script but this part executes if the 'sid' cookie exists, what this does is it first updates the sessions table with the new session id with the exisiting sid cookie and then it is supposed to update the sid cookie with the new session id as well but what really happens is that the table does update with the new session id, but the cookie stays with the old on and the second query doesn't return a correct result because it is trying to get a record for the old session id which doesn't exist anymore. Any ideas on how I can get the sid cookie to update after the table is updated?
    SK

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the problem appear in every browser? Cause your code should normally work.

    You can try removing the cookie first and place a new one then.

  6. #6
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OT:
    PHP Code:
    $sql "UPDATE "
    $sql.= "sessions "
    $sql.= "SET "
    $sql.= "sid = '" session_id() . "', time = now() "
    $sql.= "WHERE "
    $sql.= "sid = '" $_COOKIE['sid'] . "'"
    $query mysql_query($sql); 
    You should really write your sql statements into one line and not 5.

    On topic: What is the point of generating a cookie that carries the session id, which is stored in a server side cookie anyway ?


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
  •