Load session_start() only if session does not exist?

前端 未结 5 1248
不知归路
不知归路 2020-12-15 22:15

is there a short code trick to check if a session has started and if not then load one? Currently I receive an error \"session already started...\" if I put in a session sta

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 22:47

    try this condition

    if (version_compare(phpversion(), '5.4.0', '<')) {
     if(session_id() == '') {
        session_start();
     } }else{
    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    } }
    

    If you only want to avoid the error, use @ before the function example:

    @session_start();
    

提交回复
热议问题