7

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

  • create_session.php
  • QandATable.php
  • 个人标记.php
  • 惩罚.php
  • 完成.php

现在我担心的是用户可以完成其中的一些页面,然后要么通过忽略其他页面而放弃创建考试,要么他们开始通过上面的一些页面创建考试,但随后能够继续上一页或前一页或通过输入其他即将出现的页面的 URL 跳过页面。

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

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

如果用户放弃了诸如 individualmarks.php 之类的页面,并且用户直接返回到 indivdualmarks.php 页面,那很好,但如果他们尝试访问另一个页面,我正在考虑发送提示框或其他东西类似的说法:

您当前已经有一个考试正在创建中,要继续创建当前考试,请单击此链接(指向当前页面用户的链接已打开)

如果您想创建新考试,请单击此链接(链接到 create_session.php 页面)。

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

我正在使用 IE、Chrome。Safari、火狐和 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 语句留空以让用户执行该步骤吗?
4

2 回答 2

3

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

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

顺便说一句,您似乎正在从头开始构建您的应用程序。快速通道是使用框架,例如CakePHP。我建议使用 Cake,因为我刚刚发现了这个不错的插件(我自己从未使用过,但 API 非常好,而且 Cake 本身非常适合学习)

于 2013-01-03T00:42:17.723 回答
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
}

编辑:回答问题:

$currentStep 变量应该等于什么?

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

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

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

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

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

于 2013-01-03T00:49:43.790 回答