How can a user be redirected to the homepage after entering the correct Captcha code in PHP?

When a user enters the correct Captcha code in PHP, you can redirect them to the homepage by using the header() function to send a raw HTTP header to the browser with the location of the homepage. This will automatically redirect the user to the specified page.

// Check if the Captcha code is correct
if ($_POST['captcha'] == $_SESSION['captcha']) {
    // Redirect to the homepage
    header('Location: homepage.php');
    exit();
} else {
    // Handle incorrect Captcha code
    echo 'Incorrect Captcha code. Please try again.';
}