What is the function used to redirect to a different URL in PHP?
To redirect to a different URL in PHP, you can use the header() function with the 'Location' parameter. This function sends a raw HTTP header to the browser, which then redirects the user to the specified URL. It is important to note that the header() function must be called before any actual output is sent to the browser to avoid any errors.
<?php
// Redirect to a different URL
header("Location: https://www.example.com");
exit;
?>
Related Questions
- What are the best practices for passing multiple variables via URL in PHP?
- What PHP function can be used to determine the day of the week and how can it be integrated into a script that requires the calendar week to start on Sunday?
- How can the integration of PHP and HTML be optimized to maintain code clarity and organization, especially when using variable variables or complex data structures?