2

so if i fill all the fields and submit everything is great,once i do that again everything is ok,but when i press back i can see what was echoed before and once again back and then i can see the result from 1st time. i want that i cant press back or i can press back only once.

<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!";

                }


}

thanks !

LauroSkr
  • 2,159
  • 2
  • 15
  • 15

1 Answers1

1

Disabling the back button cannot be guaranteed to work (due to browser implementations), but it is discussed here: how to stop browser back button using javascript

There is no way to guarantee that the browser will not submit the same data twice (while loading, the client can press reload). Also, you can't ensure that the browser will not redisplay an old page to the user when pressing back.

If it is important not to process old data, you should design the app for idempotence. This can be achieved with SESSION variables or a database. On easy example is

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

This code will only run once and it wont hurt if the user reloads the page.

If you want to allow the user to run the action again (e.g. after the transaction is completed) you can just:

unset ($_SESSION['submitted'])
Community
  • 1
  • 1
William Entriken
  • 37,208
  • 23
  • 149
  • 195