PHP 7.2 Warning: “Cannot change session name when session is active”

前端 未结 3 527
孤城傲影
孤城傲影 2020-12-09 16:58

Since PHP on our server was upgraded to 7.2 from 7.0. I am getting the following warning (which leads to error) if a new deployment is done. The reason is probably, that old

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 17:06

    I had a similar problem but finally found a way through. The code below was my first approach that gave me errors.

    static function startmysession($lifetime, $path, $domain, $secure, $httponly){
    
        session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
        session_regenerate_id(true);
    
        if(!isset($_SESSION)){
            session_start();
        }
    }
    

    Now Earlier versions of php overlooked our mistake(We were practically renaming and giving a session that already exists properties which is very wrong. So how did i solve this problem?

    static function startmysession($lifetime, $path, $domain, $secure, $httponly){      
        if(!isset($_SESSION)){  
             session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
             @session_regenerate_id(true);    
                 session_start();
             }    
        }
    

    I now bound the session_set_cookie_params() just before session start and I test if the session already exists before doing so.

提交回复
热议问题