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

kavva's avatar

Laravel 5.1 logout after page refresh

Good afternoon ;)

I would like to ask for your help. I already created ticket on SO for this, but with one answer, that didnt help, I hope I might get answer here.

So here it is: in very short, I made fresh install of Laravel 5.1 via composer, set everything necessary and it runs without problem. After I followed documentation to create login/register/logout, etc. All works fine, except there is one very important issue.

Everytime I navigate to other page, or refresh current page, I'm instantly logged out. Session are set for 4 hours(tried file/db driver, set timezone), storage folder has its rights and followed the documentation of 5.1 and also videos from Laracast. Thing is same with socialite. Login easily, db record creation, but after refresh Im logged out (session still there, also remember token). Tried this on my mamp, on live hosting server, same result.

Does anyone else experienced this? Thank you for any ideas.

0 likes
6 replies
mstnorris's avatar

I haven't noticed this issue. Can you check if the session is there in the console?

kfirba's avatar

@kavva it sounds like somewhere it set that your session driver is Array..

kavva's avatar

Hi,

in console (Chrome) I have laravel_session and XSRF_TOKEN in cookies tab. Session storage is empty. And currently I have set session for database and those are being refreshed all the time.

kavva's avatar

@kfirba I just double checked it and both env and config is set to database. Was file before.

aivis's avatar

I had the same issue when I was using dump() in controller/repository/middleware etc. But this happened only because I was using Auth::loginUsingId(1); in the auth middleware... I was doing some debuging and was too lazy to login to my development site so I edited the auth middleware. Probably not your case :)

For example: a route /test with auth middleware and I have some dump("whatever") in the route.

When I go to example.com/test I am automatically logged in, and when I refresh the page a new session is created.

Once I replaced loginUsingId with actual login page this worked fine: go to example.com/test -> redirect to login page -> submit form -> redirect back to /test, now if I refresh the page a new session is not created.

kavva's avatar

Hi @aivis thanks for hint and sorry for delay with answer. I wasn't able to fix it. I pulled bootstraped version of Laravel 5.1 from github - https://github.com/mrakodol/Laravel-5-Bootstrap-3-Starter-Site

I that one works. I checked the settings, how is auth made and its the same. But this one works. Same machine, same mamp, .. I dont know what kind of sorcery is this, but at least it works now :)

Thanks

Please or to participate in this conversation.