What role does the header function play in redirecting URLs in PHP scripts?
The header function in PHP is used to send a raw HTTP header to the client. It is commonly used for URL redirection by sending a "Location" header with the new URL. This allows the server to redirect the user to a different page or URL.
<?php
// Redirect to a new URL
header('Location: https://www.example.com/newpage.php');
exit;
?>
Related Questions
- What is the correct way to insert a variable value into a target table when merging tables from different databases in PHP?
- What best practices should be followed when combining HTML output and database queries in PHP scripts?
- In the context of PHP usage, what are the best practices for handling data exchange between multiple windows in a web application?