Bonjour,
Voila je rencontre un petit problème avec mon code.
En faite mon site à un système de notification, pour afficher les notifications j'utilise un foreach qui a parcous ma DB, sauf que lorsque j'utilise une page externe et qu'elle a un header location j'obtient une erreur :
Cannot modify header information - headers already sent by (output started at C:\wamp\www\All\MonSite\inc\header.php:155) in C:\wamp\www\All\MonSite\contact.php on line 21
Il faut savoir que mon système de notification est présent dans mon header (menu) du site qui lui même est présent sur toutes les pages du site.
Voici le code :
Ma page header (Présent sur tout le site à chaque page du site) (Je mais seulement la parti qui fait bugger)
<div class="hidden" id="alert" style="position:absolute; background-color:#34495e; width:350px; padding:20px 0; margin-top:20px; z-index:999; delay-transition:5s;height:401px; overflow-y:scroll ">
<span class="glyphicon glyphicon-triangle-top" aria-hidden="true" style="position:absolute; top:-15px; font-size:20px; color:#34495e;"></span>
<ul style="padding:0 20px;" class="nav">
<?php require_once ($_SERVER['DOCUMENT_ROOT'] . WEBROOT .'/inc/db.php');
$pseudo = $_SESSION['auth']->username;
$select = $pdo->query("SELECT * FROM ticket WHERE pseudo='$pseudo' && answer = 1");
$tickets = $select->fetchAll();
foreach ($tickets as $ticket): ?>
<li style="margin:10px 0;">
<div class="">
<img src="avatar/generate/avatar_Pareil.png" alt="" style="width:50px;"/>
<div style="display:inline-block; vertical-align:middle; margin-left:10px;">
<h5 style="color:#fff; margin:0"><u>Réponse au ticket</u></h5>
<p style="color:#fff;"><?= sizeTexte($ticket->message, 21) ; ?></p>
</div>
</div>
</li>
<hr/>
<?php endforeach; ?>
</ul>
</div>
</a></li>
(Par exemple pour la page contact)
if(!empty($_POST['message'])){
$message = htmlspecialchars($_POST['message']);
$pseudo = $_SESSION['auth']->username;
if(!empty($_POST['email'])){
$email = htmlspecialchars($_POST['email']);
}else{
$email = $_SESSION['auth']->email;
}
require 'inc/db.php';
$pdo->prepare('INSERT INTO ticket SET pseudo = ?, message = ?, email = ?, answer = 0')->execute([$pseudo, $message, $email]);
mail("MonEmail@hotmail.fr", "Ticket de $email" , "$message \n \n Email provenant de : $email");
header("Location:index.php");
//$_SESSION['flash']['success'] = "Le message à bien été envoyé !";
exit();
}
J'aimerait du coup un moyen ou une alternative de pouvoir corriger cette erreur.
Voici l'erreur :
Cannot modify header information - headers already sent by (output started at C:\wamp\www\All\MonSite\inc\header.php:155) in C:\wamp\www\All\MonSite\contact.php on line 21
Merci de votre aide ;) !
Bonjour,
Mais, le header("Location:index.php"); n'a jamais fait bugger mon site c'est lors de la mise en place du foreach qui à tous fait bugger, du coup je devrais le placer à quel endroit le header("Location:index.php"), si tu peut m'aider ^^' ?
Le message d'erreur signifie que le serveur a reçu des information avant le header de la page. Je ne pense pas que ce soit le foreach qui fasse bugger ta page.
As tu essayer de l'enlever pour affirmer ça ?
Axis oui je l'ai enlever pour confirmer cela ;) ! Si je l'enlève tous fonctionne parfaitement...
Oui, le var_dump($tickets) me renvoie bien tous les résultats car je peut les affichers.
Voilà il me renvoie bien un array ou j'affiche dans mon code le message de l'array
array (size=2)
0 =>
object(stdClass)[6]
public 'id' => string '1' (length=1)
public 'pseudo' => string 'Pareil' (length=6)
public 'message' => string 'sdfg' (length=4)
public 'email' => string 'email@hotmail.fr' (length=21)
public 'answer' => string '1' (length=1)
public 'text_answer' => string '' (length=0)
1 =>
object(stdClass)[7]
public 'id' => string '2' (length=1)
public 'pseudo' => string 'Pareil' (length=6)
public 'message' => string 'sdgf' (length=4)
public 'email' => string 'email@hotmail.fr' (length=21)
public 'answer' => string '1' (length=1)
public 'text_answer' => string '' (length=0)