Skip to main content

How to Delete $_POST Variable On Page Refreshing with PHP

The $_POST variable stores all the information that is sent to a PHP page via the POST method. This can include text input, files uploaded, and data from form fields. If you want to delete this information when the page refreshes, you can use the PHP unset() function.

The $_POST variable keeps all the data that is sent to a PHP page via the POST method, even if the page is reloaded. This can include text input, files uploaded, and data from form fields. If you want to delete this information when the page refreshes, you need to implement a workaround.

When you make an online request, the data in your POST headers is sent again no matter what you do. The most simple solution would be to redirect users back instead of sending them new information each time they refresh their browser window or tab.

//redirect user to any page
header('Location: https://example.com/form-handling/');
header('Location: ' . $_SERVER['HTTP_REFERER']);
header("Location: ".$_SERVER['REQUEST_URI']);

By continuing to use the site, you agree to the use of cookies.