In PHP, is there any harm in running session_start() multiple times?

前端 未结 7 828
臣服心动
臣服心动 2020-12-03 13:37

Presumably there\'s some tiny performance hit, but beyond that?

相关标签:
7条回答
  • 2020-12-03 13:59

    If it produces an error, odds are that the developers didn't intend for that particular action to occur. So yes, despite what you're shown by W3Schools, it's technically a 'bad' thing to do.

    So, rather than play it safe and try to set the session on each page, why not first check to see if the session exists before you move forward?

      if ( !isset($_SESSION) ) session_start();
    

    Personally, I'd check for the existence of the session's cookie first.

    0 讨论(0)
提交回复
热议问题