I'm usually paranoid and have: $session = \Config\Services:: session(); in most routines that I am referencing $_SESSION in.
This appears to be necessary, otherwise I find that sometimes the $_SESSION variables (like those denoting the user is signed in) go missing for a while, and the user looses some of their signed-in privileges, even though they're not signed out.
I have found that sometimes, thought different happenings, that some routines requiring $_SESSION don't have this initialization, and don't appear to have ever caused a problem in the past.
Having recently moved my little project from a Windows machine onto a Linux box, although initially there didn't seem to be a problem with $_SESSION becoming lost, as of late it's become a horrible irritation. To be fair, perhaps I've broken something somewhere... though, it appears to become lost at random intervals, even when there is no user activity (besides the background (automated) 1-minute connection-check polling from the client side using JavaScript).
My questions are as follows:
1) Is there a better way / place to invoke the $session =... initialization than in every function/method that I use it (sticking it in BaseController didn't seem to work for me in the past)?
2) At some point in the past I thought using this to initialize it would be more sensible:
if (!isset($_SESSION)) $session = \Config\Services:: session();
I found it didn't work very well (and $_SESSION still appeared to go AWOL from time-to-time). I'd be grateful if anyone could explain why, and perhaps also suggest a better way to (conditionally) reattach $_SESSION's handle.
Thanks.