Whenever you refresh the page, the form data is resubmitted. As a result $_POST
is freshly populated with the form data. Remember, HTTP is stateless. Once the page executes and the request terminates the POST data from that request is gone.
If you do not want a page refresh to resubmit the form, you need to use the POST/REDIRECT/GET pattern.
In order for this to work properly we need to use a 303 redirect. This means we need to send a 303 header with our redirect. A 303 redirect will cause the browser to reload the page without the initial HTTP POST request to be resubmitted. This includes when the user uses the back or refresh buttons.