Unset session

I use sharing hosting and I am wondering how sessions works.

For example, I use session when user submit form and when I submit data to database, I put the following lines:


Is that enough or is there any extra step I should do? When this session will be deleted from server?

You can also use session_destory() which removes all information associated with the current user session.

you have to make sure you have
session_start() at the top so you have access to the $_SESSION variables

But this will remove all sessions, I would like to keep some sessions. I was just worried if using only unset won’t spend too much resources if those session are never deleted but only unset.

You can use a custom mysql based session handler to delete the session where data is empty:

function clean($max)
    global $_sess_db;

    $old = time() - $max;

    $old = mysql_real_escape_string($old);

    $sql = "DELETE FROM sess WHERE access < '$old' or data=''";

    return mysql_query($sql, $_sess_db);