Page 1 of 1

Create a New Session Id After Each Trans in Same Window

Posted: Tue Feb 15, 2005 6:05 am
by dickey

Code: Select all

// start session
session_start();

// unset all of the session variables.  
  $_SESSION = array();

// if a (client side) cookie is set, expire it (as of 1 hr ago)
  if (isset($_COOKIEїsession_name()])){
  setcookie(session_name(), '$_COOKIEї'cookiename']' , time()-3600, '/');}

// destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.
  session_destroy();
In a nutshell I have a four step workflow app.

The session starts when step 1 posts to step 2 and the session continues through steps 3 and 4.

Upon completion the user is returned to a page where the above code is run.

I create sessions using session_start().

The problem is that the session id either persists (i.e. the script has failed to expire/delete the cookie) or the session_id is re-instated for the same browser window for a new session.

The goal is to use a single browser window, to effectively 'logout' of a session, and create a new session_id after each transaction.

Any assistance greatly appreciated.


- Andrew

Posted: Tue Feb 15, 2005 6:33 am
by n00b Saibot
haven't heard of session_destroy(), have ya!

Posted: Tue Feb 15, 2005 7:50 am
by feyd
your code has a parse error, and logic errors.. both in setcookie()

session_regenerate_id()