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

oxodesign's avatar

Session not working, creating new session for each request!

Hi

For some unknown reasons the session is not working as it should. I dont get any errors, it looks like a session file is created for every request! Im using JavaScript (ajax) to communicate with Laravel (API).

Using Laravel 5.2 and is a simple app with a small authentication (JWT) and 2 controllers.

Thanks

0 likes
3 replies
jlrdw's avatar

I am not familiar with JWT, but could it have anything to do with the new web middleware, might not but doesn't hurt to check.

Snapey's avatar

if you need sessions then your route must be inside web middleware. If in doubt, use it for everything.

oxodesign's avatar
oxodesign
OP
Best Answer
Level 8

It was a CORS issue, the client didn't send the session to the server therefore the server created a new session for each request.

Please or to participate in this conversation.