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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EltonSky
Forum Newbie
Posts: 7
Joined: Tue May 02, 2006 7:47 pm

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

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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;
(#10850)
Post Reply