How to redirect a page with header?

by elise_daugherty , in category: Third Party Scripts , 2 months ago

How to redirect a page with header?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 2 months ago

@elise_daugherty 

To redirect a page using PHP with the header function, you can use the following code:

1
2
3
4
<?php
header("Location: http://example.com/newpage.php");
exit();
?>


Make sure to replace "http://example.com/newpage.php" with the URL of the page you want to redirect to. The exit() function is important to stop the execution of any further code after the header redirect.


Keep in mind that header redirection must be done before any content is outputted to the browser. Otherwise, you may encounter errors or warnings.