0
I’m running a test site to train a little bit of php, am using $_SESSION[""] to show alerts, however, when climbing to a servidor non-local alerts stop working.
PROJECT LINK-> https://drive.google.com/file/d/0B8AhqmUgCKAfTWlSdW5TMkFzVmM/view?usp=sharing
*Bank file to import into phpi folder
header.php
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PHP I</title>
    <link rel="icon" href="favicon.png">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <link rel="stylesheet" type="text/css" href="css/padroes.css">
</head>
<body>
    <div class="header">
        <a class="title" href="index.php">NarglothStore</a>
        <nav>
            <ul>
                <a href="adiciona-produto.php"><li>Adicionar Produtos</li></a>
                <a href="estoque.php"><li>Estoque</li></a>
                <a href="login.php"><li>LogIn</li></a>
                <a href="logout.php"><li>LogOut</li></a>
                <a href="contato.php"><li>Contato</li></a>
            </ul>
        </nav>
    </div>
logicaUsuario.php
function verificaUsuario(){
    if (!usuarioEstaLogado()){
        $_SESSION["error"] = "Você não tem acesso a essa funcionalidade";
        header("Location:index.php");
        die();
    };
};
add-product.php
<?php 
require_once("header.php");
require_once("banco-categorias.php");
$categorias = listaCategorias($conexao);
$produto = array("nome" => "", "preco" => "", "descricao" => "", "categoria" => "1");
$usado = "";
require_once("logicaUsuario.php");
verificaUsuario();
?>
index php.
<?php 
    require_once("conexao.php");
    require_once("header.php");
    require_once("logicaUsuario.php");
    require_once("logica-alert.php");
    mostraAlerta("success");
    mostraAlerta("danger");
    mostraAlerta("error");
?>  
logica-Alert.php:
<?php
    function mostraAlerta($tipo){
        if (isset($_SESSION[$tipo])){
?>
            <div class="alert-box">
                <p class="alert <?= $tipo ?>"><?= $_SESSION[$tipo] ?></p>
            </div>
<?php
            unset($_SESSION[$tipo]);
        };
    };
?>
Error logs:
Warning: Cannot modify header information - headers already sent by (output started at /home/comunica/public_html/testes/murilo/phpI/header.php:26) in /home/comunica/public_html/testes/murilo/phpI/logicaUsuario.php on line 9
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/comunica/public_html/testes/murilo/phpI/header.php:26) in /home/comunica/public_html/testes/murilo/phpI/logicaUsuario.php on line 2
Need to find out if any error happens, in the first script add these two lines:
ini_set('display_errors', true); error_reporting(E_ALL);– rray
You need to see which text output the
header.phpago.– rray
@rray, how do I check and correct ?
– Murilo Melo
The second error means that a text output (html, BOM, echo, Warning or error message) came out when the header was already sent. You need to have any of these before a call from
header()– rray
I’m not making it :/
– Murilo Melo
Places the header.php content
– rray
No index.php lets include/require do
header.phpbefore theconexão.php– rray
did not work, I also tried to exchange the require_once by include on all pages, but it did not work
– Murilo Melo
I think the way is to test the index with a include/require so you isolate the problem easier
– rray
@rray, I did it, however, in all cases gave the same problem... I will zip the project and put the link here, would you like to test it there ?
– Murilo Melo