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:
unset($_SESSION['example']);
unset($_SESSION['example1']);
unset($_SESSION['example2']);
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.
JREAM
March 31, 2011, 10:52pm
3
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.
Ernie1
April 3, 2011, 9:28pm
5
You can use a custom mysql based session handler to delete the session where data is empty:
<?php
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);
}