My site will have a blog that will be accessible both by registered and not registered users.
Every page in a modern site has a “home” button.
When the user is not logged-in this leads to the welcome/landing page and when he is logged in this leads(usually) to the account page.
The problem is how am I going to understand if the user is logged in so the home button in the blog page leads to the account page?
In other words the home button’s link must be adjusted accordingly depending if the user is logged in or not.
An obvious answer is to take advantage of session functionality…nonetheless in this specific scenario I am stuck on how to use it.
Yes, typically you’d store some kind of token. I would think you’d use a cookie rather than a session variable, if you want them to be remembered when they leave the site, though I’m not 100% sure that you couldn’t use a session for that as well.
So when they log in, you set a cookie to identify them, and each time you render the home link use that information to decide which link they get. And of course when they arrive at the account page, check all over again that their login information is correct and redirect them if not - don’t assume that because the cookie is set, it must be legitimate.