发布后的浏览器后退按钮行为

时间:2018-06-27 09:32:28

标签: javascript php html

我有以下网站“ cards.php”:

<body>
<div onclick="hideOverlay()" id="overlay">
    <div class="inputClass" onclick="event.stopPropagation()">
        <form id="cardForm" method="post" action="./config/putData.php">
            <input id="firstInput" type="text" name="front" placeholder="Frage"/>
            <textarea id="back" type="text"  name="back" placeholder="Antwort"></textarea>
            <input type="submit" name="submit" value="Erstellen"/>
            <input type="hidden" name="cat" value="<?php echo $_GET["cat"]?>">
            <input type="hidden" name="sub" value="<?php echo $_GET["sub"]?>">
        </form>
    </div>
    <div id="cardText" class="inputClass" style="width: 50%; min-height: 30%;">
        <div id="topText" class="top">Antwort</div>
        <div id="currentText" class="bottom" style="font-size: 1.5em;"></div>
    </div>
</div>
<main>
  <?php 
   if(isset($_SESSION["id"]) && isset($_GET["cat"]) && isset($_GET["sub"])) {
    $i = 0;
    foreach((new SimpleXMLElement($_SESSION['xml']))->category[(int)$_GET["cat"]]->subcategory[(int)$_GET["sub"]] as $card) {
        echo "<section onClick=\"showCard(" .(int)$_GET["cat"] . ", " . (int)$_GET["sub"] . ", " . $i . ", 2)\">" . $card['front'] . "</section>";
        $i++;
    }
    echo "<section onclick=\"createCard()\">+</section>";
   } else {
    header('Location: index.php');
   }
  ?>
</main>

此php脚本“ putData.php”:

<?php
session_start();
require("settings.php");
if(isset($_SESSION["id"]) && isset($_SESSION["xml"])) {

    $xml = new SimpleXMLElement($_SESSION['xml']);

    if(isset($_POST["cat"]) && isset($_POST["sub"]) && isset($_POST["front"]) && isset($_POST["back"])) {   
        $cat = $_POST['cat'];
        $sub = $_POST['sub'];
        $question = $_POST['front'];
        $answer = $_POST['back'];

        $subcategory = $xml->xpath("category")[$cat]->xpath("subcategory")[$sub];
        $newCard = $subcategory->addChild("card");
        $newCard->addAttribute("front", $question);
        $newCard->addAttribute("back", $answer);
    }
    $xml->asXML($xmldic . "flashcards_" . $_SESSION["id"] . ".xml");
    $_SESSION['xml'] = $xml->asXML();
    header("Location: " . $_SERVER["HTTP_REFERER"]);
    } else {
    header("Location: index.php");
}
?>

用户在表格中输入内容并按下“提交”按钮后,将执行php脚本。它将输入写入xml文件,并更新会话变量“ xml”。成功完成此操作后,脚本会将用户带回到上一个站点“ cards.php”。 这按预期工作。现在的问题是,用户必须按两次浏览器上的“后退”按钮才能进入“ cards.php”之前所在的站点。我该如何预防呢?浏览器不应将“ putData.php”保存为历史记录中的访问站点。

0 个答案:

没有答案