What are the potential issues of using the header() function to redirect to another page in PHP forms?

Potential issues of using the header() function to redirect to another page in PHP forms include headers already sent errors if there is any output before the header() function is called. To solve this issue, you can use output buffering to ensure that no output is sent before the header() function is called.

<?php
ob_start(); // Start output buffering

// Your form processing code here

if ($form_valid) {
    header("Location: success.php");
    exit();
} else {
    header("Location: error.php");
    exit();
}

ob_end_flush(); // Flush the output buffer
?>