Question:

Which PHP function is used to redirect a page?

Show Hint

A common pitfall with `header()` redirects in PHP is the "headers already sent" error. This happens if you try to call `header()` after any output (even a single space or blank line outside of `<?php ... ?>` tags) has been sent.
Updated On: Jul 2, 2026
  • redirect()
  • header()
  • navigate()
  • gotoPage()
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

In web development, a redirect is a way to send both users and search engines to a different URL from the one they originally requested.
In PHP, redirects are performed by sending a raw HTTP header to the browser.
The PHP function used to send a raw HTTP header is the `header()` function.
To perform a redirect, you use the `header()` function with a "Location" header. The syntax is:
`header("Location: http://www.new-url.com");`
It is crucial that this function is called before any actual output (like HTML or `echo` statements) is sent to the browser. It's also good practice to call `exit()` immediately after the `header()` call to stop the script from executing further.
The other options (`redirect()`, `navigate()`, `gotoPage()`) are not standard built-in PHP functions for this purpose.
Was this answer helpful?
0
0