What is the correct PHP function to use for redirecting to another page?
When you want to redirect a user to another page in PHP, you can use the header() function with the Location parameter set to the URL you want to redirect to. This function sends a raw HTTP header to the browser, which tells it to redirect to the specified page. Make sure to call the header() function before any output is sent to the browser, as headers must be sent before any content.
<?php
// Redirect to another page
header("Location: http://www.example.com");
exit();
?>
Keywords
Related Questions
- How can variables be properly passed when including files in PHP to avoid issues like the one described in the forum thread?
- Are there specific features or plugins in IDEs that can help PHP developers easily navigate and trace variables and functions within their code?
- Is using sessions a recommended approach to hiding parameters in PHP links?