Say I run setcookie('sid', session_id(), time()+604800, '/', 'onlyonxbox.net'), and then close browser, then i open browser again and run that code again, wouldn't it replace the value of sid?
This is the code and it is not working:
$sql = "UPDATE ";
$sql.= "sessions ";
$sql.= "SET ";
$sql.= "sid = '" . session_id() . "', time = now() ";
$sql.= "WHERE ";
$sql.= "sid = '" . $_COOKIE['sid'] . "'";
$query = mysql_query($sql);
setcookie('sid', $sid, time()+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?