步骤.php
<?php
function allowed_in($steps){
$steps = array('Text1.php', 'Text2.php', 'Text3.php');
$latestStep = $_SESSION['latestStep'];
}
?>
文本1.php:
<?php
if(allowed_in($steps)){
//all code in the create_session.php
}
?>
我正在尝试将 php 变量存储到会话变量并访问另一个页面中的函数,但出现以下错误:
注意:未定义变量:第 28 行中的步骤
注意:未定义索引:第 49 行中的最新步骤
我只需要询问如何解决这些错误。我需要一个if(isset())
变量$_SESSION
吗?
更新:
以下是完整代码:
<?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 > 1 ) {
return 1;
} else {
return 0;
}
}
?>
create_session.php:
if(allowed_in($steps)){
//all code in the create_session.php
}else{
?>
<div class="boxed">
<a href="<?= $pages[$currentPages+1] ?>">Continue</a>
<br/>
<a href="create_session.php" id="createLink">Create New</a>
</div>
<?php
}
?>
我试图遵循的伪代码:
function allowed_in($pased_vars){
//your code
if($foo){
return 1;
}else{
return 0;
}
}
on included pages
<?php
//include file with code
if(allowed_in($vars)){
//allowed
}else{
//not
}