is confirmation needed causing undefined session variables being displayed?
<p>I have a code below where it checks to see if a teacher is logged in or not. The $_SESSION variables to check teacher's login in status through session is in the 
<code>member.php</code> script.</p>

<pre><code>&lt;?php

session_start();

include('member.php');
include('teachername.php');
...

if ((isset($username)) &amp;&amp; (isset($userid))){ 


...

}else{ 

echo "Please Login to Access this Page | &lt;a href='./teacherlogin.php'&gt;Login&lt;/a&gt;";

}

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

<p>Now If the session has expired then it displays the <code>Please Login to Access this Page</code> message which is correct. But the problem I have that is that when Sessions
have expired, it starts displaying undefined <code>$_SESSION</code> variables notices on this page as I have sessions on this page.</p>

<p>But it does not show notices on every page after session expires. It only shows it for pages where the user has to confirm to log out. You see in the <code>include(teachername.php)</code> code
it displays the log out code which is this below:</p>

<pre><code>&lt;?php

...

        echo "Logged In: &lt;b&gt;{$_SESSION['teacherforename']} {$_SESSION['teachersurname']}&lt;/b&gt; | &lt;a id='teachlogout' href='./teacherlogout.php'&gt;Logout&lt;/a&gt;";
        echo "&lt;br/&gt;&lt;a id='resetlink' href='./resetpass.php'&gt;Reset Your Password&lt;/a&gt;";

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

<p>When the user clicks on the <code>Logout</code> link, it performs a <code>session_destroy()</code> which is below:</p>

<pre><code>&lt;?php

        if ((isset($username)) &amp;&amp; (isset($userid))){

        session_destroy();

            echo "You have been Logged Out | &lt;a href='./home.php'&gt;Home&lt;/a&gt;";
        }

        else {

            echo "You are Not Logged In";

        }



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

<p>What I am asking is that is it not destroying the session variables when the session has expired in some pages because of the confirmation I have placed in these
pages where user needs to confirm before being logged out because it seems like the only pages that is having problem showing undefined session variable errors are all
on these pages, the other php scripts don't have this problem when session runs out.</p>

<p>Below is code for confirmation for logout:</p>

<pre><code>$(function() {   

    function logoutHandler() {
    return confirm("You are currently creating an Assessment, are you sure you want to logout?" + "\n" + "(Your current assessment details will be lost)" + "\n");
}

$('#teachlogout').click(logoutHandler); 
</code></pre>

<p><code>#teachlogout</code> is id of the logout link</p>
