How can the header() function in PHP be used for redirection?
The header() function in PHP can be used for redirection by sending a raw HTTP header to the browser, instructing it to redirect to a new location. This is commonly used when you want to redirect users to a different page or URL based on certain conditions in your PHP script. Example:
<?php
// Redirect to a new page after 5 seconds
header("refresh:5;url=anotherpage.php");
?>
Keywords
Related Questions
- How can PHP developers ensure that form data is properly submitted using POST method rather than GET method?
- What best practices can be implemented to ensure PHP code is compatible with modern standards and does not rely on deprecated features like REGISTER_GLOBALS?
- How can the code provided be improved in terms of security measures?