Text5.php
にアクセスすると、ステップインの undefiendd 変数が取得され続けますText2.php
。$steps
私の質問は、変数を配列として含めたので、未定義の変数を取得する方法です。
Text5.php
<?php
$steps = array(1 =>'Text1.php',2 => 'Text2.php',3 => 'Text3.php',4 => 'Text4.php',5 => 'Text6.php',6 => 'Text7.php');
function allowed_in($steps){
// 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;
}
?>
Text2.php
if (allowed_in()=== "Allowed")
{
//Text2.php code
}
else
{
$page = allowed_in()+1;
?>
<div class="boxed">
<a href="<?php echo $steps[$page] ?>">Link to Another Page</a>
</div>
<?php
}
?>