mpen
mpen

Reputation: 282875

What causes session_regenerate_id(true) to return false?

\Console::log('session_statusxxx',session_status(),ini_get('session.use_trans_sid'));
if(!session_regenerate_id(true)) { // user attempted to log in; create a new session for him
    throw new \Exception("Could not regenerate session ID");
}
\Console::log('session_statusxxx',session_status());

I'm hitting that exception -- i.e., session_regenerate_id is returning false.

Just prior to calling session_regenerate_id I can see that session_status() is 2 which is PHP_SESSION_ACTIVE, and session.use_trans_sid is "0".

Shouldn't session_regenerate_id destroy the active session and start a new one?

Upvotes: 0

Views: 400

Answers (2)

mpen
mpen

Reputation: 282875

Double check your implementation of SessionHandlerInterface if you're using session_set_save_handler. In my case, I was returning the wrong value from a few of the functions. e.g., read should return an empty string if there's no session, not false, destroy should return true or false, etc.

Upvotes: 0

exussum
exussum

Reputation: 18550

There are plenty of reasons

https://github.com/php/php-src/blob/a2d766503aed619493386a9b4ef8190be62b36f7/ext/session/session.c#L2078

They all emit warnings to give more information try showing these notices / log extra information on why it failed.

Upvotes: 1

Related Questions