sure. we can use sessions to keep track of which submission were dealing with.
<?php
session_start();
// initialize the variable
if (!isset($_SESSION['last_submission_id'])) {
$_SESSION['last_submission_id'] = '';
}
// if they submitted the form
if (isset($_POST['submission_id'])) {
// check if this submission id is the same as the last id we accepted data from
if ($_POST['submission_id'] == $_SESSION['last_submission_id']) {
echo '<h1>dont refresh the page please</h1>';
// do not accept this form
} else {
// accept the form
// since we accepted it, record the id of this form submission
$_SESSION['last_submission_id'] = $_POST['submission_id'];
}
}
// make a new one every time.
$next_submission_id = uniqid();
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="submission_id" value="<?php echo $next_submission_id; ?>">
<input type="submit">
</form>
keep in mind, this wont only stop from re-submitting the last form they submitted again. if they make, say 5 valid submission, then hit the back button 3 times, then hit refresh, this WILL allow it.
to get around that, you would have to use an array in the session to store all submission_id's.