-4

I have one "problem" with my code.I am building login page for school website and, when user clicks "logout" button it should reddirect them to page logout.php and i am using header("Location: login.php") but when someone clicks it this error appears

Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\testing\dodaci\menu.php:71) in D:\xampp\htdocs\testing\control_panel.php on line 28

But when i remove menu.php (It is navigation menu for my website, i included it in my website using PHP) Everything works fine.I don't know what is the problem.

** menu.php **

<div class="navigation">
           <ul id="menu">
    <li>
        <a href="index.php" style="margin-left:0px;">Naslovna </a>


    </li>
    <li>
        <a href="historijat.php">Historijat</a>
    </li>
    <li><font class="dropdown" >Zaposlenici<span class="icon icon-angle-down"></span></font>
        <ul class="sub-menu" style="width:170px;">
            <li>
                <a href="zaposlenici_profesori.php">Profesori</a>
            </li>
            <li>
                <a href="zaposlenici_pomocno_osoblje.php">Pomoćno osoblje</a>
            </li>



        </ul>

    </li>
    <li><font class="dropdown" >Sekcije<span class="icon icon-angle-down"></span></font>
        <ul class="sub-menu">
            <li>
                <a href="sekcije/informatika.php">Informatika</a>
            </li>
            <li>
                <a href="sekcije/matematika">Matematika</a>
            </li>

            <li>
                <a href="sekcije/biologija">Biologija</a>
            </li>

        </ul>

    </li>
    <li><font class="dropdown" >Upis u školu<span class="icon icon-angle-down"></span></font>
        <ul class="sub-menu" style="width:200px;">
            <li>
                <a href="Upis/gimnazija.php">Gimnazija</a>
            </li>
            <li>
                <a href="Upis/ekonomska.php">Ekonomska</a>
            </li>
            <li>
                <a href="Upis/sumarski_tehnicar.php">Šumarski tehničar</a>
            </li>
            <li>
                <a href="Upis/trgovacka.php">Trgovačka</a>
            </li>
            <li>
                <a href="Upis/tehnicka.php">Tehnička</a>
            </li>
        </ul>

    </li>

    <li> <a href="kontakt.php">Kontakt</a></li>
    <li><a href="#"><input style="width:145px;" type="text" name="t1" placeholder="Pretraga Učenika ..."/><input type="submit" name="submit" value="Traži" style="padding:0px 12px 0px 12px;"/></a>

    </li>


    </ul>


        </div>
Crion
  • 199
  • 1
  • 1
  • 9

3 Answers3

0

You can only post header() functions when no other data has been sent to the client.

When removing your menu.php file, I assume you do not send any information to the client before calling your header() function.

Wampie Driessen
  • 1,654
  • 1
  • 13
  • 19
0

In order for header() to work, it is required that no output is sent to the browser prior to calling the function. An output can be send even if no html is printed, but if you have a blank space outside of PHP tags, or if you use encoding with BOM.

If you MUST redirect, I suggest using the javascript alternative.

<script type="text/javascript">
<!--
window.location = "http://www.google.com/"
//-->
</script>
mariobgr
  • 2,143
  • 2
  • 16
  • 31
0

As has been mentioned, any header call must be the first code to be reached on a page. Otherwise, you will have a problem.

You can try via JavaScript:

<script>window.location = 'http://www.mywebsite.com';</script>
Ethan Turk
  • 437
  • 4
  • 8