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

ycsm's avatar
Level 1

Accessing session variable for every page

Hi guys. I have a session variable I need to check for before each page is loaded, if it isn't loaded the user gets forced logged out and redirected.

I'm trying this on the web.php page

if(!isset(session('season')->name)){ dd(session('season')->name); return redirect('logout-force')->with(Auth::logout()); }

But getting "Trying to get property 'name' of non-object"

Am I missing something here? Is there another way I should be doing this?

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

You are trying to dump and die the name property although your condition is truthy whenever it is not set. Don't try to access name.

This is functionality that could/should be implemented in a middleware, rather in web.php

2 likes
ycsm's avatar
Level 1

Thanks! I did it with middleware

Please or to participate in this conversation.