#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    16
    Rep Power
    0

    Deleting cookies and data


    Hi all,
    I'm currently destroying a cookie with the following:
    PHP Code:
    setcookie("cart_id"session_id(), time() + ((6) * 1)); 
    What would be the best way to delete data from a mySQL DB based on that session_id when it expires?

    Cheers,
    chrima
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Posts
    645
    Rep Power
    0
    how are you deleteing a cookie with a positive value in the time? unless that is a typo. also you should delete the data in the db before the cookie is deleted, if you want to use the cookie info to do the deletion. if you store the session_id in the db just delete that

    delete from table where sessionid = '{$_COOKIE["cart_id"]}'
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Coppell, TX
    Posts
    203
    Rep Power
    0
    Cookies are not the best way to keep session data around, because many users turn them off in the browser for security reasons.

    The session ID is stored in a temp file on your server, and when it expires, it automatically goes away.

    If you have written information to a MySQL database based on the session-id, then you could write a scheduled maintenance routine that runs, say, nightly, that reads your MySQL table, building an array of just the session-ids. Then compare these to the temp folder that have the "active" session-ids, and then delete the differences from the table.

    Im not sure I know of a way to "trigger" an event in the future to delete a database record unless you are using something like Oracle that has database triggers.

    Hope this helps.

    kork
    "Any significantly advanced techology is indistiguishable from magic." - Arthur C. Clarke
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Columbus, OH
    Posts
    6
    Rep Power
    0
    you could use "cron" on linux or "at" on windows to have things happen at regular intervals.

IMN logo majestic logo threadwatch logo seochat tools logo