Pages - Menu

06 November, 2012

Save session with session_regenerate_id

Session_destroy is function build in for PHP that will destroy all session in our website. For example: when I add to cart then I log out then my session in cart was destroyed all. And to avoid this problem occur we can use this paragraph {
$oldSession = session_id();
session_regenerate_id();
$newSession = session_id();
session_id($oldSession);


session_destroy();

$oldSession = $_SESSION;
session_id($newSession);
session_start();
$_SESSION = $oldSession;
}

session_regenerate_id() function could help us to solve this problem because we could keep our session to display even though we log out (clear session). Does anybody has good solution more than that? Please share any idea on it.

No comments:

Post a Comment