1

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.

Community
  • 1
  • 1
Jacobian
  • 7,972
  • 22
  • 92
  • 184
  • `===` is a [comparison operator](http://php.net/manual/en/language.operators.comparison.php), means that values are equal and the same type. – umka May 22 '15 at 11:38
  • The triple equal sign is to check for variable type as well. Check [this](http://stackoverflow.com/a/80649/1057527). – machineaddict May 22 '15 at 11:39
  • Thanks, for clarifying terminology, but still why `===` and not `!=` in this case ? What is the sense of using this comparison operator in the context of the problem? – Jacobian May 22 '15 at 11:40

0 Answers0