-1

I have one big problem:

I've been working on a project and always gives me this error:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\output\index.php:60) in C:\xampp\htdocs\output\Login.php on line 40

I tried everything, but it does not work... I tried remove html and when I remove all html and remain only form to submit data then already works...

On line 60 in index.php have only <?php ... On line 40 in Login.php have header('Location: profile.php');

This is index.php file:

<?php
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require './Login.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="bg-BG" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#" itemscope itemtype="http://schema.org/Article">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <div class="lightbox_bg" id="lightbox_bg" style="display: none;"></div>
        <div class="box_bg1">
            <div class="lightbox_registration lightbox" style="display:none">
                <a href="#" class="lightbox_close"></a>
                <h1>text </h1>
                <p>text </p>
            </div>
            <div id="site">
                <a href="index.php" class="logo"></a>
                <ul class="topMenu">
                    <li><a class=" "  href="materialy/materialy.html">text</a></li>
                    <li><a class=" "  href="prirucka/index.php">text</a></li>
                    <li><a class=" showLightbox topRegistrace" rel=".lightbox_registration" href="#">Register</a></li>
                </ul>
                <div class="clearboth"></div>
                <form action="" method="post" id="frm-loginEmailForm">
                    <div class="clearboth"></div>
                    <div class="toplista">
                        <div class="label"><label for="frmloginEmailForm-email">e-mail </label>:</div>
                        <input type="text" class="textwhite" name="email" id="frmloginEmailForm-email" required="required" data-nette-rules="{op:':filled',msg:&quot;\u041c\u043e\u043b\u044f, \u0432\u044a\u0432\u0435\u0434\u0435\u0442\u0435 e-mail \u0430\u0434\u0440\u0435\u0441\u044a\u0442, \u043a\u043e\u0439\u0442\u043e \u0441\u0442\u0435 \u043f\u043e\u0441\u043e\u0447\u0438\u043b\u0438 \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f\u0442\u0430. &quot;},{op:':email',msg:&quot;\u041c\u043e\u043b\u044f, \u0432\u044a\u0432\u0435\u0434\u0435\u0442\u0435 \u0432\u0430\u043b\u0438\u0434\u0435\u043d \u0435-mail \u0430\u0434\u0440\u0435\u0441.  &quot;}" value="" />
                        <div class="label"><label for="frmloginEmailForm-password">Pass</label>:</div>
                        <input type="password" class="textwhite" name="password" id="frmloginEmailForm-password" required="required" data-nette-rules="{op:':filled',msg:&quot;\u041c\u043e\u043b\u044f, \u0432\u044a\u0432\u0435\u0434\u0435\u0442\u0435 \u043f\u0430\u0440\u043e\u043b\u0430. &quot;},{op:':minLength',msg:&quot;\u0412\u044a\u0432\u0435\u043b\u0438 \u0441\u0442\u0435 \u0442\u0432\u044a\u0440\u0434\u0435 \u043a\u0440\u0430\u0442\u043a\u0430 \u043f\u0430\u0440\u043e\u043b\u0430. &quot;,arg:2}" />
                        <input type="hidden" name="login" value="1">
                            <input type="submit" class="blackbutton" name="odeslat" id="frmloginEmailForm-odeslat" value="Login" />
                    </div>
                </form>
                <div id="hlasky" class="hide">text </div>
                <div id="obsah">
                    <div class="lightbox lightbox_medialni" style="display:none">
                        <a href="#" class="lightbox_close"></a>
                        <h1>text</h1>
                        <div>
                        </div>
                        <div class="clearleft"></div>
                    </div>
                    <div class="lightbox lightbox_dalsi" style="display:none">
                        <a href="#" class="lightbox_close"></a>
                        <h1>text</h1>
                        <div>
                        </div>
                        <div class="clearleft"></div>
                    </div>
                    <div class="box_content">
                    </div>
                </div>
            </div>
        </div>
        <?php
        if (isset($_POST['login']) && $_POST['login'] == 1) {
            Login::LoginUser($_POST['email'], $_POST['password']);
        }
        ?>
    </body>
</html>
Antonio
  • 21
  • 1
  • 7

1 Answers1

0

you must make sure No output is sent before sending headers. as stated in this answer:

Functions that send/modify HTTP headers must be invoked before any output is made. Otherwise the call fails

Community
  • 1
  • 1
Nitsan Baleli
  • 5,393
  • 3
  • 30
  • 52
  • Yes, I know. However, in index.php have only html and one php if. when all html is removed, leaving only the post form is already working and redirects... – Antonio Oct 11 '14 at 11:59
  • @Antonio Then you have your answer. Don't output HTML before you set headers. Headers have to be the first thing being set. It's not saying "the first PHP". It's the first content. HTML/text/javascript/pictures/whatever needs to be *after* setting headers. – h2ooooooo Oct 11 '14 at 11:59
  • @Antonio you must then make changes to your code – Nitsan Baleli Oct 11 '14 at 12:05
  • @Nitsan Baleli Ok, but where? I have other projects that work the same way and they do not have a problems. The difference is that this project html code is not written by me... – Antonio Oct 11 '14 at 12:11
  • @Antonio this is beyond the scope of your question. You can ask another question, and provide more of your code, but then again, trying to output anything before header change is a no-no. – Nitsan Baleli Oct 11 '14 at 12:14
  • I put the code from index.php :) if necessary I will put code from Login.php – Antonio Oct 11 '14 at 12:25
  • @Antonio you should ask another question. and accept this answer if it helped you IMO – Nitsan Baleli Oct 11 '14 at 12:36
  • Will not be a problem for stackoverflow system if I create a new question? If not, I will create it. – Antonio Oct 11 '14 at 12:41
  • I don't think it was the right course to advise the OP to post another question - how to fix this is part of the same question, surely? In any case, both questions are duplicates - questions of this kind are best not answered at all. – halfer Oct 11 '14 at 14:04