is structure of code causing undefined $_SESSION variables?
<p>When I navigate to a page which is locked (in other words when the box which states you have to <code>Continue</code> appears, I am getting undefined <code>$_SESSION</code> variables. Before I included the <code>if (allowed_in()=== "Allowed"){</code> statement, I was not getting any undefined $_SESSION variables but as  now need that if statement, Im starting to get those variable errors.</p>

<p>For the <code>$_SESSION</code> undefined errors, is it because I am placing the $_SESSION variables in the wrong place? </p>

<p>Below is an example <code>QandATable.php</code> order of code looks like:</p>

<pre><code>        &lt;?php

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

        session_start();
        include('steps.php'); //exteranlised steps.php

?&gt;
        &lt;head&gt;

&lt;?php
        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;

            }

        elseif (isset($_POST['submitDetails']) &amp;&amp; $_SESSION['sessionCount'] &lt; $_SESSION['sessionNum']) {
            $_SESSION['sessionCount']++;
        }
?&gt;

        &lt;/head&gt;

        &lt;body&gt;

        &lt;?php 

    //once session is expired, it should log the user out, but at mo this isn't happening
        if ((isset($username)) &amp;&amp; (isset($userid))){ //checks if user is logged in

            if (allowed_in()=== "Allowed"){

        //QandATable.php code:

        }else{

        $page = allowed_in()+1;


        ?&gt;

        &lt;div class="boxed"&gt;
          &lt;a href="&lt;?php echo $steps[$page] ?&gt;"&gt;Continue with Current Assessment&lt;/a&gt;

        &lt;?php   

        }

        }else{ 

        echo "Please Login to Access this Page | &lt;a href='./teacherlogin.php'&gt;Login&lt;/a&gt;"; 
        //show above echo if user is not logged in

        }

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

<p>Below is the full steps.php:</p>

<pre><code>&lt;?php

$steps = array(1 =&gt;'create_session.php',2 =&gt; 'QandATable.php',3 =&gt; 'individualmarks.php',4 =&gt; 'penalty.php',5 =&gt; 'penaltymarks',6 =&gt; 'complete.php');

function allowed_in($steps = array()){
// Track $latestStep in either a session variable
// $currentStep will be dependent upon the page you're on

if(isset($_SESSION['latestStep'])){
   $latestStep = $_SESSION['latestStep'];
}
else{
   $latestStep = 0;
}
$currentStep = basename(__FILE__); 

$currentIdx = array_search($currentStep, $steps);
$latestIdx = array_search($latestStep, $steps);

if ($currentIdx - $latestIdx == 1 )
    {
       $currentIdx = $_SESSION['latestStep'];
       return 'Allowed';
    }
    return $latestIdx;
}

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