2

因此,如果我填写所有字段并提交一切都很好,一旦我再次这样做,一切都很好,但是当我按下返回时,我可以看到之前和再次返回的内容,然后我可以看到第一次的结果。我希望我不能按回,或者我只能按一次。

<form action="Alauris.php" method="POST">
question1 <input type="text" name="answer1"><br>
question2 <input type="text"  name="answer2"><br>
question3 <input type="text"  name="answer3"><br>
question4 <input type="text"  name="answer4"><br>
question5 <input type="text"  name="answer5"><br>
question6 <input type="text"  name="answer6"><br>
question7 <input type="text"  name="answer7"><br>
question8 <input type="text"  name="answer8"><br>
<input type="submit" value="Make">
</form>





<?php 

if(isset($_POST['answer1'])&&isset($_POST['answer2'])&&isset($_POST['answer3'])&&isset($_POST['answer4'])&&isset($_POST['answer5'])&&isset($_POST['answer6'])&&isset($_POST['answer7'])&&isset($_POST['answer8'])){

    $answer1=$_POST['answer1'];
    $answer2=$_POST['answer2'];
    $answer3=$_POST['answer3'];
    $answer4=$_POST['answer4'];
    $answer5=$_POST['answer5'];
    $answer6=$_POST['answer6'];
    $answer7=$_POST['answer7'];
    $answer8=$_POST['answer8'];

                if(!empty($answer1)&&!empty($answer2)&&!empty($answer3)&&!empty($answer4)&&!empty($answer5)&&!empty($answer6)&&!empty($answer7)&&!empty($answer8)){
                           $content = "asdasda" .$answer1. '<br>'."asdas".'<br>'.$answer2."5t64356456a".'<br>'.$answer3. "asdasdasda".$answer4."5t643564".$answer5. "aasda".'<br>'.$answer6."5t64356456as".$answer7. "asdasdas45".$answer8."5t64356456a45";

                           echo $content;


                }else{

                     echo "fill all fields,my friend!";

                }


}

谢谢 !

4

1 回答 1

1

不能保证禁用后退按钮有效(由于浏览器实现),但这里讨论:how to stop browser back button using javascript

无法保证浏览器不会两次提交相同的数据(加载时,客户端可以按reload)。此外,您无法确保浏览器在按下返回时不会向用户重新显示旧页面。

如果不处理旧数据很重要,则应将应用程序设计为幂等性。这可以通过 SESSION 变量或数据库来实现。简单的例子是

if (isset($_SESSION['submitted']) {
    doWork();
    $_SESSION['submitted'] = 1;
}

此代码只会运行一次,如果用户重新加载页面也不会受到影响。

如果您想允许用户再次运行该操作(例如在事务完成后),您可以:

unset ($_SESSION['submitted'])
于 2013-10-23T13:38:02.753 回答