Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8501429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:12:39+00:00 2026-06-11T01:12:39+00:00

I am having problem with a session variable. The problem is that with a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:12:41+00:00Added an answer on June 11, 2026 at 1:12 am

    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:

    if( ! isset( $_SESSION['my_var'] ) )
    {
      // This session doesn't exist anymore - I'd better head over to the start page...
      header('Location: index.php');
      exit;
    }
    

    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:

    setcookie('my_var', 'My Value', time() + 60 * 60 * 24 * 3); // a cookie lasting three days
    

    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:

    if( ! isset( $_COOKIES['my_var'] ) )
    {
      // This cookie doesn't exist anymore - I'd better head over to the start page...
      header('Location: index.php');
      exit;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a page that requires a session variable which will be inserted into
I'm having a problem in identifying a session timeout page and a page navigated
I'm having a problem of losing session variable on my website. It append at
I've having a problem with an Array that I'm storing in the session variables.
I'm having problems with retrieving multiple instances of a session variable from an InProc
I am having a problem with using session variables. I have two controllers named
I have a ColdFusion session variable that's a structure of data. My goal is
so i am having a problem passing php session variables to multiple pages. Essentially
I am having problem setting a variable in PHP for multiple use into if
Hey guys I am having a VERY difficult time with a specific problem in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.