PHP How to Differentiate Between Form POST and Page Refresh

PHP Code to Distinguish Between a Form Post and a Page Refresh which Prevents Double Form Post Processing on the Server

Home Short:

To distinguish between an actual form submssion of $_POST values and a page reload or refresh prevent multiple form submission processing in php ...

  1. create a $_SESSION variable such as $_SESSION["form_token"]
  2. Insert the token into a hidden element on the pages form.
  3. On the page where the form is posted and processed in php, check for the presence of this token and that this token matches or equals $_SESSION["form_token"].

On the Page where the Form is

In the php code ...

In the html code for the form insert this hidden element ...

On the Page where the Form $_POST Values are Processed

The function that checks if this is an actual $_POST or page refresh

The code that calls the function to check if valid $_POST or page refresh

S
H
A
R
E