I consulted this and this link, but still I'm not sure what is the right workaround of this problem (which I face in my application from time to time). At least I do not understand why this seemingly most general solution
if(session_id() === '') session_regenerate_id($deleteOldSession);
should work. What looks strange is a comparison operator ===
. It seems to me, that the problem happens when there is no session file and so session_id() should be empty. So, I guess this is what we should try to avoid - to destroy session, when in fact it does not exist. So, why ===
and not:
if(session_id() != '') session_regenerate_id($deleteOldSession);
I should add that in my application session_regenerate_id(true)
is heavily used and this procedure is invoked hundreds of times per user. But still this error pops up once or twice a day.