What is the recommended approach for confirming account deletion using PHP?

When deleting a user account in a web application, it is important to confirm the deletion to prevent accidental data loss. One recommended approach is to display a confirmation message to the user before proceeding with the deletion. This can be achieved by using a modal dialog or a separate confirmation page.

<?php
// Check if the user has confirmed account deletion
if(isset($_POST['confirm_delete'])){
    // Code to delete the user account
    // Redirect to a confirmation page or display a success message
    echo "Account deleted successfully.";
} else {
    // Display a confirmation message to the user
    echo "Are you sure you want to delete your account?";
    echo "<form method='post'><input type='submit' name='confirm_delete' value='Confirm'></form>";
}
?>