A redirect that never redirects is one of the most confusing PHP experiences. You write header('Location: dashboard.php') , the page stays put, and PHP answers with:
Warning: Cannot modify header information - headers already sent
Enter fullscreen mode
Exit fullscreen mode
The script does not crash. It just silently ignores your header. Here are the five mistakes I see most often, and the one-line fix for each.
1. A blank line before <?php
A single space or newline before the opening tag is output. PHP sends the headers the moment the first byte leaves the script, so your later header() call arrives too late.
Fix: make <?php the very first characters of the file. Nothing before it β not even a blank line.
2. Echoing something before the redirect
echo 'Welcome back' ; header ( 'Location: dashboard.php' ) ; // Warning
Enter fullscreen mode
Exit fullscreen mode
The echo is body output, and body output seals the headers.β¦