如何锁定其他网页

use*_*871 7 php ajax jquery

我有一个考试应用程序,用户创建考试时必须通过这些页面:

  • create_session.php
  • QandATable.php
  • indivdiualmarks.php
  • penalty.php
  • complete.php

现在我担心的是用户可以完成其中的一些页面但是放弃创建考试时通过省略其他页面或者他们开始​​通过上面的一些页面创建考试但是然后能够重新开始通过输入即将出现的其他页面的URL,可以显示上一页或上一页或跳过页面.

所以我的问题是,有没有办法可以阻止用户跳过页面或返回到以前的页面?换句话说,他们必须按照确切的顺序按照上面五页的确切步骤来创建考试.

例如,如果用户在QandATable.php page,那么他们无法返回到create_session.php页面,或者QandATable.php在成功提交之前他们无法跳到其他页面?换句话说,锁定除当前页面之外的其他页面.一旦用户访问了该complete.php页面,则检查完成,并且create_session.php可以从锁定中删除,因为这是第一页.

如果用户放弃了诸如individualmarks.php之类的页面,并且用户直接返回到indivdualmarks.php页面,那就没问题了,但是如果他们试图访问另一个页面,我想发送一个提示框或者某个东西类似的陈述:

您目前正在创建考试,要继续创建当前考试,请单击此链接(链接到当前页面用户已启用)

如果您想创建一个新的考试,请点击此链接(链接到create_session.php页面).

我知道我要问的不是很简单,但我不希望用户搞砸创建考试,除非他们按照正确的顺序执行每个步骤(每个页面),这样就不会弄乱任何数据.有没有人有一个关于如何实现这一目标的简单样本?

我正在使用IE,Chrome.Safari,Firefox和Opera

谢谢

更新:

<?php

session_start();

?>

    <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="stepsStyle.css">
        <title>Follow Steps</title>

        <script type="text/javascript">

//if user selects "Create New Assessment" Link, then use jquery/ajax below
//code below will access removesession.php where it will remove exam details which will be overwritten

$(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>

        </head>
        <body>

<?php

$steps = array('create_session.php', 'QandATable.php', 'individualmarks.php', 'penalty.php', 'complete.php');

$latestStep = $_SESSION['latestStep'];
// Track $latestStep in either a session variable or the DB and retrieve accordingly
// $currentStep will be dependent upon the page you're on

$currentIdx = array_search($currentStep, $steps);
$latestIdx = array_search($latestStep, $steps);

if ($currentIdx - $latestIdx > 1 ) {
    ?>

//set up a div box to display message on wether use should contine or not
<div class="boxed">
  You already have an exam currently in creation, to continue with creating the current exam click on this link: <br/><a href="">Continue with Current Assessment</a>
<br/>
If you want to create a new exam then please click on this link: <br/><a href="create_session.php" id="createLink">Create New Assessment</a>
</div>

<?

} else {
    // let the user do the step
}

?>
Run Code Online (Sandbox Code Playgroud)

关于上面的代码有几个问题:

  1. $currentStep变量应该等于什么?
  2. 如果用户想要继续当前考试,如何链接到当前页面?
  3. 我应该将else语句留空以让用户执行此步骤吗?

ern*_*nie 1

我会在变量中跟踪最后完成的状态,并在列表中跟踪工作流程。在每个页面上,检查最后完成的状态是否大于或等于之前所需的步骤。这是假设您的工作流程是完全线性的。像这样的东西:

$steps = array('create', 'table', 'marks', 'penalty', 'complete');

// Track $latestStep in either a session variable or the DB and retrieve accordingly
// $currentStep will be dependent upon the page you're on

$currentIdx = array_search($currentStep, $steps);
$latestIdx = array_search($latestStep, $steps);

if ($currentIdx - $latestIdx > 1 ) {
    // show error message
} else {
    // let the user do the step
}
Run Code Online (Sandbox Code Playgroud)

编辑:回答问题:

$currentStep 变量应该等于什么?

这应该等于您所在的页面并与 $steps 中的值匹配;看起来它应该是当前页面的文件名。

如果用户想继续当前考试,如何链接到当前页面?

听起来好像您在询问如果用户位于页面上如何重定向到正确的步骤。下一步应该是$steps[$latestIdx + 1],例如最新步骤之后的步骤。

我是否应该将 else 语句留空以让用户执行该步骤?

else 语句应包含您希望用户执行的所有代码。或者,如果您要将其外部化,则可能应该使用返回值,如果他们可以执行该步骤,则返回 1,如果不能,则返回 0。然后在每个页面上,您将调用此函数,并根据返回值显示页面或显示错误。