How can the redirect function be improved to ensure the correct ID is passed in the URL in PHP?

The issue with the current redirect function is that it does not include the correct ID in the URL when redirecting. To ensure the correct ID is passed in the URL, we can modify the redirect function to accept an additional parameter for the ID and append it to the URL.

function redirect($url, $id) {
    header('Location: ' . $url . '?id=' . $id);
    exit();
}

// Example of how to use the improved redirect function
$id = 123;
redirect('https://example.com/page.php', $id);