Undefined variable: _SESSION when sending variables via post through JavaScript trigger

前端 未结 8 497
执念已碎
执念已碎 2020-12-14 15:49

In my index.php file I call session_start() and set a couple of session variables. In a second PHP file I would like to access these session variables.

相关标签:
8条回答
  • 2020-12-14 16:29
    session_start();  
    

    is the answer of most of topic like this. i have been struggling with this issue and i solve my problem with this code

        if (version_compare(PHP_VERSION, '5.4.0', '<')) {
            if(session_id() == '') {session_start();}
        } else  {
           if (session_status() == PHP_SESSION_NONE) {session_start();}
        }
    
    0 讨论(0)
  • 2020-12-14 16:29

    I had this problem and tried different ways and finally found a solution :

    PHP is case sensitive, Use $_SESSION instead of $_session in all php files.certainly It works . Example :

    <?php
    session_save_path('tmp/'); (is not optional - it is mandatory)
    session_start();
    echo $_SESSION["s1"]."<br/>";
    echo $_SESSION["s2"]."<br/>";
    ?>
    
    0 讨论(0)
提交回复
热议问题