How do i check if session_start has been entered?

前端 未结 10 1511
走了就别回头了
走了就别回头了 2020-12-09 09:00

I have a third party script and was wondering how I can check with PHP if session_start() has been declared before doing something?



        
相关标签:
10条回答
  • 2020-12-09 09:55
    
        if(defined('SID'))
            // do
    
    0 讨论(0)
  • 2020-12-09 09:56

    If session already started, Error: "Fatal error: Can't use function return value in write context"

    Try this:

    $session = session_id();
    if(empty($session)){ 
        session_start();
    }
    
    0 讨论(0)
  • 2020-12-09 10:00
    if(!isset($_SESSION)) {
         session_start();
    }
    

    The check will allow you to keep your current session active even if it's a loop back submission application where you plan to reuse the form if data is typed incorrectly or have additional checks and balances within your program before proceeding to the next program.

    0 讨论(0)
  • 2020-12-09 10:03

    for php >= 5.4.0

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

    for php < 5.4.0

    if(session_id() == '') {
    session_start();
    }
    
    0 讨论(0)
提交回复
热议问题