1
訪問Text2.php
時,我一直收到Text5.php
中的步驟undefiendd變量。我的問題是怎麼來的我amgetting未定義的變量,因爲我已經包括了可變$steps
作爲數組:不斷獲取數組的udefined變量
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
}
?>
什麼Text2.php和Text5.php具有互辦?他們怎麼叫?他們是否在相同的範圍內?他們是不同的HTTP請求? –
您還應該得到另一個錯誤,類似於***警告:**在調用allowed_in()*時缺少參數1。當你沒有將正確的參數傳遞給函數時,你期望發生什麼? – DCoder
發佈的代碼甚至沒有語法上的有效('echo $ steps [$ page []') –