What role does the header() function play in PHP and how can it be utilized for page redirection within a script?
The header() function in PHP is used to send a raw HTTP header to the client. It is commonly used for page redirection within a script by sending a "Location" header with the desired URL. This can be useful for redirecting users after form submissions, authentication, or any other scenario where a page needs to be redirected programmatically.
<?php
// Redirect to a new page after 3 seconds
header("Refresh: 3; url=destination_page.php");
exit;
?>
Keywords
Related Questions
- What are the best practices for combining DELETE statements with SELECT queries in PHP for SQL operations?
- In what situations is it recommended to use PHP for form validation, and when should other technologies like Ajax be considered instead?
- How can PHP be used to redirect visitors to the homepage if they are accessing a protected file from an external source?