所以,如果我填写所有字段并提交一切都很棒,一旦我再次这样做一切都很好,但是当我按回来时我可以看到之前回复的内容再次回来然后我可以看到第1个结果时间。我希望我不能按回来,否则我只能按回一次。
<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!";
}
}
谢谢!
答案 0 :(得分:1)
无法保证禁用后退按钮(由于浏览器实施),但在此处讨论:how to stop browser back button using javascript
无法保证浏览器不会两次提交相同的数据(加载时,客户端可以按重新加载)。此外,您无法确保在按下时浏览器不会向用户重新显示旧页面。
如果重要的是不处理旧数据,则应该为idempotence设计应用程序。这可以通过SESSION变量或数据库来实现。简单的例子是
if (isset($_SESSION['submitted']) {
doWork();
$_SESSION['submitted'] = 1;
}
此代码只运行一次,如果用户重新加载页面,它不会受到伤害。
如果您想允许用户再次运行操作(例如,在交易完成后),您可以:
unset ($_SESSION['submitted'])