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

  • SEARCH
  • Home
  • 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 9117997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:01:57+00:00 2026-06-17T05:01:57+00:00

I have a page which contains $_SESSION variables. Now after a certain amount of

  • 0

I have a page which contains $_SESSION variables. Now after a certain amount of time, all the sessions will expire which is fair enough. But the problem is that suddenly we get undefined notices on our $_SESSION variables as they are now expired.

So in this situation what is the best thing to do when a session expires. DO we just include a the E ^ NOTICE code in order to not show notices (afterwe know the page is fully complete with no errors), or are we expected to destroy a session using session_destroy() on the page, or is there other ways of not showing these undefined errors to the users who are viewing these pages on the browser and may view the page when the session has expired.

Below is my example code I have on how I have $_SESSION code displayed:

 <?php

    ini_set('session.gc_maxlifetime',12*60*60); //12 hours until session expires
    ini_set('session.gc_divisor', '1');
    ini_set('session.gc_probability', '1');
    ini_set('session.cookie_lifetime', '0');
    require_once 'init.php'; 

    session_start();  //starts sessions

    include('member.php');  //this php script also contains sessions


    if (isset($_POST['id'])) {

    $_SESSION['id'] = $_POST['id'];

    }


    if(isset($_POST['sessionNum'])){
                //Declare my counter for the first time

                $_SESSION['initial_count'] = $_POST['sessionNum'];
                $_SESSION['sessionNum'] = intval($_POST['sessionNum']);
                $_SESSION['sessionCount'] = 1;

        }

    if (isset($_POST['submitDetails']) && $_SESSION['sessionCount'] < $_SESSION['sessionNum']) {
        $_SESSION['sessionCount']++;
    }


    $sessionMinus =  $_SESSION['sessionCount'];


    if (isset($_POST['textQuestion'])) {

    $_SESSION['textQuestion'] = $_POST['textQuestion'];

    }

    if (isset($_POST['textMarks'])) {

    $_SESSION['textMarks'] = $_POST['textMarks'];

    }

    if (isset($_POST['totalWeight'])) {

    $_SESSION['totalWeight'] = $_POST['totalWeight'];

    }

    if ($sessionMinus == $_SESSION['initial_count']){ 

        $action = 'individualmarks.php'; 

    }elseif($sessionMinus != $_SESSION['initial_count']){ 

        $action = $_SERVER['PHP_SELF']; 

    }

    ?>
  • 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-17T05:01:59+00:00Added an answer on June 17, 2026 at 5:01 am

    Check for the presence of a particular sentinel value. e.g. if whatever you’re doing with the session is for a login-protected system, then check the value of
    isset($_SESSION['loggedIn']) && ($_SESSION['loggedIn'] == true).

    If the sentinel value(s) are not present, then something’s happened to the session, and you should redirect the user elsewhere to restore things to the way they should be (e.g. show the login page).

    Since you can’t know in advance what page a “slow” user will hit, you have to assume the session can vanish at any time, and do the sentinel checks on EVERY page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read the page in Emacs wiki which contains a list of session
I have a page which contains a html.RenderPartial, that renders an ASP.NET MVC partial
I have a page which contains a jQuery-UI horizontal slider, created using a little
I have a page which contains profiles of various members of a company and
I have a page which contains a dynamically generated grid, where a user can
I have a child page LoginContent.aspx which contains a login form. If the user
I have an html page called search.html which contains sliders, they work perfectly in
I have this html page which is very simple, it contains a text box
I have one drop down list in my page, which contains two options. What
I'm pretty new to PHP and have a String which contains an HTML page.

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.