undefined variable and undefined index
<p><strong>steps.php</strong>    </p>

<pre><code>&lt;?php        
    function allowed_in($steps){        
    $steps = array('Text1.php', 'Text2.php', 'Text3.php');                
    $latestStep = $_SESSION['latestStep'];            
    }        
?&gt;
</code></pre>

<p><strong>Text1.php:</strong></p>

<pre><code>&lt;?php
   if(allowed_in($steps)){      
      //all code in the create_session.php             
   }
?&gt;
</code></pre>

<p>I am trying to store a php variable to a session vairable and access a function in another page but I am getting the following errors:</p>

<blockquote>
  <p>Notice: Undefined variable: steps in ... on line 28<br>
  Notice: Undefined index: latestStep in ... on line 49</p>
</blockquote>

<p>I just need to ask how to fix these errors. Do I need an <code>if(isset())</code> for the <code>$_SESSION</code> variable? </p>

<p><strong>UPDATE:</strong></p>

<p>Below is full code:</p>

<pre><code>    &lt;?php

    function allowed_in($steps){

    $steps = array('create_session.php', 'QandATable.php', 'individualmarks.php', 'penalty.php', 'penaltymarks', 'complete.php');

    // 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 = "";
}
    $currentStep = basename(__FILE__); 

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

    if ($currentIdx - $latestIdx &gt; 1 ) {

       return 1;

    } else {

        return 0;

    }

    }

    ?&gt;

    create_session.php:
    if(allowed_in($steps)){

    //all code in the create_session.php

    }else{
    ?&gt;

    &lt;div class="boxed"&gt;
      &lt;a href="&lt;?= $pages[$currentPages+1] ?&gt;"&gt;Continue&lt;/a&gt;
    &lt;br/&gt;
    &lt;a href="create_session.php" id="createLink"&gt;Create New&lt;/a&gt;
    &lt;/div&gt;

    &lt;?php   

    }

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

<p>The pseudo code I am trying to follow:</p>

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

//your code

if($foo){
    return 1;
}else{
    return 0;
}

}

on included pages
&lt;?php
//include file with code

if(allowed_in($vars)){
//allowed
}else{
//not
}
</code></pre>
