Header() redirect error

Asked

Viewed 120 times

0

<?php
require_once("banco-produtos.php");
require_once("logicaUsuario.php");
verificaUsuario();
require_once("header.php");

$id = $_POST['id'];

removeProduto($conexao, $id);
$_SESSION["success"] = "Produto removido com sucesso";
header("Location:estoque.php");
die();

logicaUsuario.php

function verificaUsuario(){
    if (!usuarioEstaLogado()){
        $_SESSION["error"] = "Você não tem acesso a essa funcionalidade";
        header("Location:index.php");
        die();
    };
};

php database.

require_once("conexao.php");
function removeProduto($conexao, $id){
    $query = "delete from produtos where id = {$id}";
    return mysqli_query($conexao, $query);
};

Error_log

Warning: Cannot modify header information - headers already sent by (output started at /home/comunica/public_html/testes/murilo/phpI/header.php:23) in /home/comunica/public_html/testes/murilo/phpI/remove-produto.php on line 11

I followed the tips given in two other questions, one mine and another that had been marked as duplicate of the previous, but none of them solved my problem, I’ve modified the code as many times as possible, I tried to put the header() and/or user verification.

  • @Wallacemaxters, read the description of the question, I already tried to use what they had put in this other question there, but it did not work, it keeps generating this error...

  • 2

    I have read the description of the question and have come to the conclusion that it is duplicated. All possible causes for the problem are reported in this question in the duplication reference. If you are experiencing another problem, you need to go into more detail.

  • I know they are reported, I followed what was there and still continued the same mistake

  • Murilo, but honestly, did you see how many answers there are in the other question? Are you sure you tried everything and it didn’t work? The solution to the problem is that, there is no other explanation. Even, if this is the case, your question would be closed in the same way, if you do not know how to report in detail the problem occurred (we could close as "this problem cannot be reproduced").

  • 1

    Maybe you have another problem that is not described in the question, like another file with a blank code at the beginning. A good test to be done is to give a CTRL+U on the error page and see if there is nothing being sent to the browser before (this is spoken in one of the linked responses)

  • tried dude, I’m since 10:40 in the morning trying to solve this problem, had some other smaller that I solved, but just missing that same

Show 1 more comment

1 answer

1


I will try to explain the following mistake:

Warning: Cannot modify header information - headers already sent by (output started at /home/comunica/public_html/testes/murilo/phpI/header.php:23) in /home/comunica/public_html/testes/murilo/phpI/remove-produto.php on line 11

It says: "You cannot modify headers after you have already sent an outputbuffer (output)".

For the previously posted topic, in the archive header.php there are output buffers (HTML code), resulting in this Warning.

Any modification of Header must be done before any output, be the include(), require() or even a echo with the outputbuffer connected.

  • 1

    It was not I who gave the negative, but it was practically what was already answered in the other question. This question has already been indicated as duplicate.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.