Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ltrain's avatar

What's the point of changing session ids on login?

Been having some issue's with race conditions on multiple ajax requests happening concurrently and wondering if anyone know's why the session id is changed on log in?

https://github.com/laravel/framework/blob/4.2/src/Illuminate/Auth/Guard.php#L455

https://github.com/laravel/framework/blob/4.2/src/Illuminate/Session/Store.php#L207

0 likes
9 replies
bashy's avatar

That's the whole point of sessions. They get destroyed on logout and regenerated on login?

1 like
ltrain's avatar

That would make sense to me if there was only a session when the user was logged in, but I believe Laravel always has a session regardless of whether the user is authenticated or not so based on that I don't get why the session id is changed on login.

pstephan1187's avatar

@bashy, You could keep the session id you had before logging in once you log in and just append the "logged in" information to that session id and go on your merry way. However, the danger here is session hijacking. If someone is sniffing your wifi when you login, they will be able to pretend they are you and be logged in as well. But if you change the session id, it offers another layer of security, making it harder for the perpetrator to hijack your session. I don't know exactly how it all works, but I understand this to be a best practice and that is [one of] the reason[s] why.

2 likes
bashy's avatar

Oh I get what you mean now. Non-auth session ID gets regenerated upon logging in.

peter-mw's avatar

Hi, i am using session to add items to shopping cart and now all my cart is lost upon login

pstephan1187's avatar

@peter-mw, you need to start your own thread. You won't get good answers posting your question at the end of another person's thread. Someone should be able to help you there :)

akshay56495's avatar

hey can anyone tell me, on login page of my website if i change the original session id to random one but with same length of 41 characters and able to login. then would that count as a vulnerability.

Please or to participate in this conversation.