php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74309 example2 is missing old session data backup
Submitted: 2017-03-24 15:01 UTC Modified: 2019-01-02 00:39 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: bburnichon at gmail dot com Assigned:
Status: Open Package: Session related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2017-03-24 15:01 UTC] bburnichon at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.session-regenerate-id
---

Currently, in the new session, data is lost.

function my_session_regenerate_id() {
    // Backup data to allow later restore
    $old_session_data = $_SESSION;
    
    // New session ID is required to set proper session ID
    // when session ID is not set due to unstable network.
    $new_session_id = session_create_id();
    $_SESSION['new_session_id'] = $new_session_id;
    
    // Set destroy timestamp
    $_SESSION['destroyed'] = time();

    // Write and close current session;
    session_commit();

    // Start session with new session ID
    session_id($new_session_id);
    ini_set('session.use_strict_mode', 0);
    session_start();
    ini_set('session.use_strict_mode', 1);
    
    // Restore data from old session as session_start created a new array reference in $_SESSION
    $_SESSION = $old_session_data;
}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-02 00:39 UTC] girgias@php.net
-Package: Documentation problem +Package: Session related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC