以下では、ユーザーが現在のページを表示している場合、配列内の他のすべてのページがロックアウトされ(アクセスできない)、ユーザーが現在のページを完了するまで他のページにアクセスできない機能を作成しようとしています。の上。
以下は、6つのphpスクリプトを処理するコードです。
<script type="text/javascript">
$(function() {
var link = $("#createLink");
link.click(function() {
$.ajax({
url: "removesession.php",
async: false,
type: "POST",
success: function() {
window.location.href = link.attr("href");
}
});
//cancels the links true action of navigation
return false;
});
);
</script>
<?php
$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
$latestStep = $_SESSION['latestStep'];
$currentStep = basename(__FILE__);
$currentIdx = array_search($currentStep, $steps);
$latestIdx = array_search($latestStep, $steps);
if ($currentIdx - $latestIdx > 1 ) {
?>
<div class="boxed">
<a href="<?= $pages[$currentPages+1] ?>">Continue</a>
<br/><a href="create_session.php" id="createLink">Create New</a>
</div>
<?
} else {
// let the user do the step
}
?>
だからここに何が起こる可能性があるかの例があります:
- ユーザーが
penalty.php
ページにいるため、アレイ内の他のページがロックアウトされています ユーザーが別のページにアクセスしようとすると、上記のdivボックスが表示されます。
ユーザーがリンクを選択した場合
Continue
、ユーザーはそのページに移動する必要がありpenalty.php
ます。Create New
ユーザーがリンクを選択した場合は、に移動しcreate_session.php
てjquery / ajaxメソッドを実行removesession.php
し、バックグラウンドでスクリプトに移動する必要があります
上記のコードはとして知られているphpスクリプトにsteps.php
あり、これは外部化されているため、を使用してアクセスできますinclude(steps.php)
。これは、配列内の6つのphpスクリプトに含まれているため、これらのスクリプトはこれらのページにアクセスできます。
今私の質問は、このコードでもう1つ行う必要があるということです。これは、上記のコードにあるif / elseステートメントを処理し、他のスクリプトにコードを含めます。
戻り値を使用して、ユーザーがステップを実行できる場合は1を返し、実行できない場合は0を返します。次に、各ページでこの関数を呼び出し、戻り値に応じて、ページを表示するか、エラーを表示します。
私の質問は、上記の引用で言及されているものをコーディングする方法をまったく知らないようだということです。誰かがif/elseステートメントがどのように見えるべきか、そしてそのスクリプトで関数を呼び出せるようにするために6のphpスクリプトの1つにどのコードを含めるべきかを示すことができますか?
アップデート:
Steps.php
<?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
$latestStep = $_SESSION['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
}
?>