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 best way to set a cookie with a specific content that can be read later, potentially weeks or longer after it was set?
- What are common pitfalls to avoid when implementing username uniqueness in PHP registration forms?
- Are there specific server configurations or hosting environments where accessing the php.ini file to adjust settings may not be possible?