How to make a redirect in PHP
Send a Location header, then stop the script:
<?php
header("Location: https://example.com/new-page", true, 302);
exit;- Call it before any output (HTML, spaces, echo). Otherwise PHP reports "headers already sent".
- Always call
exitafter it, or the rest of the script keeps running. - Use 301 for a permanent move and 302 for a temporary one.