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

rouby7634's avatar

Laravel 8 session not persist when redirect to the home (root) page

I'm working on Laravel 8 website, on the local environment the site works well, the issue appeared after deployment on cpanel, the process works as follows, after login successfully the user is redirected to profile page, the problem is seen when redirecting to the (root) home page, the session is not persist,

i've changed the session_drive from 'file' to 'database' however the problem not solved, also added the web middleware to web routes but not solved the problem

0 likes
5 replies
Snapey's avatar

You don't need to add web middleware, its already there. Adding it twice will cause issues.

Open your browser dev tools and see if you are getting the Laravel session cookie.

rouby7634's avatar

@Snapey Thanks Snapey, You are right according the web middleware, i've seen the laravel session cookie in my browser as follows two laravel_session & two XSRF-TOKEN one with Domain: ".domain.com" and the other with Domain: "www.domain.com" moreover i noticed that cookie parameter "Expires / Max-Age:" is the same as the current time

rouby7634's avatar

@Snapey Also i've created a new laravel project, it worked fine short time and the issue came again without changing any settings, could the issue related to the server or somthig?

Snapey's avatar

@rouby7634 puzzled why you had cookies for both domain.com and www.domain.com implying that you ate redirecting to the wrong domain at some point

rouby7634's avatar

@Snapey I solved the cookie repetition as there were old cookies saved in the sessions table, the unusual staff is the cookie Max-age/ Expires in the same as current time, i noticed that it's the same cookie Max-age/ Expires as on local server

Please or to participate in this conversation.