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);
Keywords
Related Questions
- What is the purpose of using number_format in PHP and how does it work?
- What are the common errors that may occur when including PHP files and classes, and how can they be resolved?
- How can the use of trim() function in PHP help in removing unnecessary whitespaces from strings while processing text files?