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
- In what situations would it be more beneficial to use a database instead of text-based files for storing and retrieving data in PHP scripts, and how can this transition be made smoothly?
- What are common errors in PHP coding that can lead to undefined constant or variable notices?
- How can PHP developers test and verify the behavior of session handling in their applications?