I am having problem with a session variable. The problem is that with a session variable, after a period amount of time, if the user refreshes a page or something like that, it will start displaying notices stating that there are some undefined indexes.
Now I want to still use session variables but how can I keep the session going for longer? I have heard that we developers can use something like tokens so that even if the user becomes idle for a day or two or even longer, that when they refresh the page or navigate to another page, there won’t be any undefined indexes notices appearing on screen.
Does anyone have any examples on using tokens?
Thanks
Session variables are for sessions – by default, they have a short lifespan (20 minutes or so).
This means that when your session has timed out, you will start seeing notices for session variables no longer defined, when trying to use them (at least if you have error reporting with notices enabled).
Normally, you check if the session variable exist – and handle it if it doesn’t:
Now, I wouldn’t recommend you to set the lifetime of a session up to two or three days. Instead, you should take a look at setting cookies and defining the content and lifespan for each of these:
Though, you will have the same issue with notices on the forth day if you don’t check up on the existence of the cookie: