简体   繁体   中英

php session is lost on redirect

I am trying to use secure sessions here. This is a piece of code i adopted while researching. Unfortunately the session does not load when the headers are redirected. Could someone please explain what is happening and point me in the right direction.

Here's the code

if(!isset($_SESSION))
    {
        $dir_path = ini_get("session.save_path") . DIRECTORY_SEPARATOR . _SESSION_DIR;
        if(!is_dir($dir_path)) mkdir($dir_path);

        if( ini_get('session.use_trans_sid') == true) {
            ini_set('url_rewriter.tags' , '');
            ini_set('session.use_trans_sid' , false);
        }

        $lifetime = 60 * 60 * 24 * 1;
        //$lifetime = 60;
        ini_set('session.gc_maxlifetime' , $lifetime);
        ini_set('session.gc_divisor' , '1');
        ini_set('session.gc_probability' , '1');
        ini_set('session.cookie_lifetime' , '0');
        ini_set('session.save_path', $dir_path);
        session_name(_SESSION_NAME);
        session_start();

If you are looking to retrieve sessions that were created on a previous page, You have to make sure that you used a session_write_close() after you wrote your sessions. Then in order to use them on subsequent pages you have to call session_start() BEFORE you can use them. You can see more on sessions here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM