RE: How to prevent a form from being submitted again?

How to prevent a form from being submitted again?

ankit Senior Developer Asked on June 9, 2018 in HTML.
Add Comment
1 Answers

You can prevent form re-submission using a session variable.
Code:


<form action="" method="post">

<?php

$randnumber=rand();

$_SESSION['RANDNUMBER']=$randnumber;

?>

<input type="hidden" value="<?php echo $randnumber; ?>" name="checkNumber" />

<!-- The Rest of Fields will be goes here -->

<input type="submit" name="submit" value="submit" />

</form>


After check session variable $_SESSION[‘RANDNUMBER’] with textbox $_POST[‘checkNumber’] value Like

<?php

if(isset($_POST['submit']) && $_POST['checkNumber']==$_SESSION['RANDNUMBER'])

{

//Your Code will be goes here

}

?>

Team Leader Answered on November 7, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.