Steps.php
<?php
function allowed_in($steps){
$steps = array('Text1.php', 'Text2.php', 'Text3.php');
$latestStep = $_SESSION['latestStep'];
}
?>
Text1.php:
<?php
if(allowed_in($steps)){
//all code in the create_session.php
}
?>
php変数をセッション変数に保存し、別のページの関数にアクセスしようとしていますが、次のエラーが発生します。
注意:未定義の変数:28行目の...のステップ
注意:未定義のインデックス:49行目の...のlatestStep
これらのエラーを修正する方法を尋ねる必要があります。変数にが必要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
}