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

前端 未结 8 507
执念已碎
执念已碎 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:21

    I also encountered the same problem recently. I could not access the contents of the $_SESSION variable.

    1) This was as a result of trying to access the $_SESSION variable before the declaration of session_start(); In my own case, I had already started a session in a header.php file. But I was accessing the $_SESSION variable before the include statement. Example;

     
    
    

    instead of doing something like this

    
     
    

    2) Another thing that may cause this problem, maybe a failure to start a session at the top of all the files that may require access to the $_SESSION variable using

    session_start();
    

    Hope this helps anybody that stumbles on the same problem. Although this is coming at a late hour.

提交回复
热议问题