How can PHP prevent data from being saved multiple times when the browser's refresh button is clicked?
When the browser's refresh button is clicked, it resubmits the form data, causing it to be saved multiple times. To prevent this, we can use a technique called Post/Redirect/Get (PRG) pattern. After processing the form data, we redirect the user to a different page using the header() function to prevent the form data from being resubmitted when the refresh button is clicked.
// Process form data
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Save the data to the database
// Redirect to a different page
header("Location: success.php");
exit();
}
Related Questions
- Is it possible to automatically create a new directory for uploaded files and assign a numerical name to each directory using PHP?
- Why might it be necessary to specify the request method (e.g., POST) in a cURL request made with PHP, even when no data is being transferred?
- Are there specific configurations or settings in the php.ini file that need to be adjusted for Interbase support in PHP on Linux?