What should we do when a session expires while we still view a page?
<p>I have a page which contains <code>$_SESSION</code> 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.</p>

<p>So in this situation what is the best thing to do when a session expires. DO we just include a the <code>E ^ NOTICE</code> 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 <code>session_destroy()</code> 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.</p>

<p>Below is my example code I have on how I have $_SESSION code displayed:</p>

<pre><code> &lt;?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']) &amp;&amp; $_SESSION['sessionCount'] &lt; $_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']; 

    }

    ?&gt;
</code></pre>
