如何锁定其他网页


How to lock out other web pages

我有一个考试应用程序,用户要创建一个考试,他们必须经过这些页面:

  • 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这样的页面,并且用户直接返回到individualmarks.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
}
?>

对上面的代码有几个问题:

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

通过模糊实现安全性确实是一种幼稚的方案:您应该始终假设您的url是公共的。这里需要一个类似于向导的接口,它是一个有限状态机。假设您的系统已经有用户,您需要找到一个工作流引擎(或FSM实现,或自己开发一个简单的)并跟踪每个流程中的用户提交。

在每个页面的开始,你必须验证用户的位置,即你必须说明用户在当前状态是否可以访问所请求的资源。如果他不能直接重定向,则显示所请求的页面。

顺便说一句,你似乎是从头开始构建你的应用程序。快速通道是使用框架,例如CakePHP。我建议蛋糕,因为我刚刚发现了这个很好的插件(我从来没有使用过它,但API真的很好,蛋糕本身是伟大的学习目的)

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

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

编辑:回答问题:

$currentStep变量应该等于什么?

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

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

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

我应该让else语句为空让用户执行该步骤吗?

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