Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shivamyadav's avatar

php error?

error

Cannot modify header information - headers already sent by (output started at C:\laragon\www\php phonebook project\crud\School Management System\components\navbar.php:69) in C:\laragon\www\php phonebook project\crud\School Management System\controller\login.php on line 15

my code of components\navbar.php:69

 <a href="/forms/login" class=" hover:bg-blue-500 hover:rounded-xl hover:py-2 hover:px-2
                                <?php echo $_SERVER['PHP_SELF'] == '/forms/login/index.php' ? "bg-blue-700 rounded-xl py-2 px-2" : "" ?>  
                                flex gap-5
                                ">
                                <i class="fa-solid fa-at fa-2x"></i>
                                <span class="ml-2">Login</span>
                            </a>

code of controller\login.php

   header('location:/');
0 likes
1 reply
Sergiu17's avatar

https://www.php.net/manual/en/function.header.php it's related to this:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Please or to participate in this conversation.