doulue7522 2016-09-14 15:14
浏览 180
已采纳

练习使用session_start()

Should I use

session_start()

or

if (session_id() == ""){
  session_start();
}

because I remember correctly that without the latter there will be another error message?

  • 写回答

4条回答 默认 最新

  • dougong8012 2016-09-14 15:16
    关注

    Recommended way for versions of PHP >= 5.4.0

    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }
    

    Source: http://www.php.net/manual/en/function.session-status.php

    For versions of PHP < 5.4.0

    if(session_id() == '') {
        session_start();
    }
    

    Both of these should work for what you are asking for.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?