Page 1 of 1

how can I use old $_SESSION[] after session_regenerate_id?

Posted: Tue May 23, 2006 12:40 am
by EltonSky
Hello mates,

I m trying to make a session secure, so i use session_regenerate_id() after each session_start(). But i still want to use infomation stored in $_SESSION[] from previous page. I try to do:

Code: Select all

$old_id = session_id();
session_regenerate_id()
$new_id = session_id(); 
session_id($old_id);
but still lost my prevous $_SESSION[].

Does anybody know some apporoach to hanle this?


REGARDS,

Elton

Posted: Tue May 23, 2006 12:54 am
by Christopher
You are losing your session data because you are changing the session id back to the old one. You just need to do the following and it should work:

Code: Select all

session_start();
session_regenerate_id();

// then you can use the session
$myvar = $_SESSION['myvar'];
$_SESSION['myothervar'] = $myothervar;