0

I am trying to refresh a PHP page on form submit only once. My issue is that I have multiple form elements on this page each updating something or the other. So I click on one of the form submit and I want to refresh the page only once, but using the code below:

echo '<meta http-equiv="Refresh" content="0;' . $page . '">';

the page keeps on reloading itself again and again. Is there a way I can get out of this loop without affecting other form elements?

1 Answers1

0

You can submit your forms with the POST method. Then detect the POST request, and meta refresh with GET method (which is the default).

Detect the POST like this:

if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {}

See these questions:

Detecting request type in PHP (GET, POST, PUT or DELETE)

How to detect if $_POST is set?

Look into RESTful architecture on when to use POST vs. GET:

https://en.wikipedia.org/wiki/Representational_state_transfer

Community
  • 1
  • 1
Tim Grant
  • 3,300
  • 4
  • 23
  • 31