When submitting a form to the same PHP page, what is the correct method to find if the page was accidentally updated and not sent again?
Here is what I am using now:
$tmp = implode('',$_POST); $myHash = md5($tmp); if(isset($_SESSION["myHash"]) && $_SESSION["myHash"] == $myHash) { header("Location: index.php"); // page refreshed, send user somewhere else die(); } else { $_SESSION["myHash"] = $myHash; } // continue processing...
Is there something wrong with this solution?
UPDATE: An example of this scenario would be inserting a row into a registration table. You would like this operation to be performed once.
, . , , , , , . - .
<?php $token = /* a randomly generated string */; $_SESSION['_token'] = $token; ?> <input type="hidden" name="_token" value="<?php echo $token; ?>" />
. , , POST.
Re comment: . , , SO, . , , .
. , .
, , POST, . , , . , . , ( ).
, POST , ,
header("Location: new-page.php");
- .
Using tokens in combination with a POST / REDIRECT / GET design pattern is the best solution available.
Source: https://habr.com/ru/post/1741376/More articles:Is ASP.Net State Server an elegant solution? - asp.net-mvcbash: how to find out the NUM parameter in grep -A -B on the fly? - bashGroovy Eclipse Autoformat? - code-formattingResharper plugin for sorting methods in alphabetical order? - sortingКомпилировать OpenSSH для использования в приложении iphone - objective-cПолучение первого результата из запроса LINQ - почему ElementAt (0) терпит неудачу, когда First () преуспевает? - c#Displaying a hash map of coordinates in sleep mode with annotation - javaHow to remove unrecognized characters that are returned from a web service? - javaPhp file upload function - phpHow to save URL parameters when writing custom 404 error page? - asp.netAll Articles