在Text5.php
访问Text2.php
. 我的问题是我为什么会得到一个未定义的变量,因为我已将变量包含$steps
为数组:
文本5.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;
}
?>
文本2.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
}
?>