I use PHP sessions with session_start() to maintain state of which user is logged into my site. This works fine by just calling session_start() and the top of all my files once the user is logged in.
However, I’d like to have it so when they click the site’s icon in the menu bar, if they are logged in it won’t send them to the homepage but rather to their logged in personal page. However, a simple session_start() to recognize the user is logged in and redirect them at the top of the homepage does not work.
None of the session variables are recognized from the home page. Yet the session is not actually killed – I can go back in the history and am still logged into the site. Would there be a reason the homepage should give different behavior than every other page?
No, it shouldn’t be different.
In order to see what variables are available in your $_SESSION, you can do this
If it’s empty then there is a problem. You can try to see the session_id with the method
It should be the same session_id in both your logged page and home page. If this is not the case, maybe you are messing up with cookies?