How can PHP developers provide users with a confirmation message after submitting a form?
After a user submits a form, PHP developers can provide a confirmation message by redirecting the user to a new page that displays the message. This can be achieved by setting a session variable before the redirect and then checking for this variable on the new page to display the confirmation message.
// On the form submission page
session_start();
$_SESSION['confirmation_message'] = "Form submitted successfully.";
header("Location: confirmation_page.php");
exit();
// On the confirmation_page.php
session_start();
if(isset($_SESSION['confirmation_message'])) {
echo $_SESSION['confirmation_message'];
unset($_SESSION['confirmation_message']);
}