Précédent   Forum des professionnels en informatique > PHP > Langage > Débuter
Débuter Forum d'entraide pour débuter en PHP. Avant de poster -> Cours PHP, FAQ PHP, Outils PHP, etc.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 15/06/2011, 11h34   #1
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
Par défaut bizarre pas de warning pour ceci ? output avant header sans bufferisation

bonjour tout le monde,

regardez ce code :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
</head>
 
<body>
<h1>Salut !</h1>
<?php
echo "<h1>Salut !</h1>";
echo "Salut !";
header("Location: page.php");
?>
</body>
</html>
je trouve partout sur internet qu'un code comme ceci génère un warning

Citation:
Warning: Cannot modify header information - headers already sent by (output started at xxxxxxx ...
mais ici ca ne m'a pas généré cette erreur et la redirection passe avec success.

j ai EasyPHP-5.3.5.0 .

y a t-il quelqu'un qui pourrait m'expliquer ca !

merci
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 11h37   #2
Membre éprouvé
 
Homme romain escudier
Développeur informatique
Inscription : juin 2011
Messages : 300
Détails du profil
Informations personnelles :
Nom : Homme romain escudier
Âge : 22
Localisation : France, Ille et Vilaine (Bretagne)

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2011
Messages : 300
Points : 471
Points : 471
Dans ton code tu ne modifie pas le header, tu ecris juste du code php, donc je pense pas que sa te genere une erreur.
__________________
Pas de solution, pas de probleme

Une réponse utile (ou +1) le pouce vert
Une réponse à votre question

skeud est déconnecté   Envoyer un message privé Réponse avec citation 02
Vieux 15/06/2011, 11h47   #3
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
Pardon ! je ne comprends pas !
pouvez vous expliquer ?
merci
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 12h05   #4
Modérateur
 
Avatar de Benjamin Delespierre
 
Benjamin Delespierre
Développeur Web
Inscription : février 2010
Messages : 2 984
Détails du profil
Informations personnelles :
Nom : Benjamin Delespierre
Âge : 24
Localisation : France

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : février 2010
Messages : 2 984
Points : 5 016
Points : 5 016
Mets l'error reporting au max et l'erreur devrait se montrer

Code :
1
2
3
4
<?php
error_reporting(E_ALL | E_DEPRECATED | E_USER_NOTICE | E_NOTICE);
ini_set('display_errors', 1);
?>
__________________
A la recherche d'un framework MVC facile a prendre en main ? Essayez Axiom
Nouveau: la référence d'Axiom est disponible sur GitHub (je la peaufine en ce moment même).

Un problème correctement identifié est à moitié résolu, évitez de poster l'intégralité de votre code avec pour seule explication "ça ne marche pas...".
Pour identifier correctement vos problèmes PHP, utilisez la gestion des erreurs et xdebug.

Les boutons et existent, servez-vous en
Benjamin Delespierre est déconnecté   Envoyer un message privé Réponse avec citation 11
Vieux 15/06/2011, 12h13   #5
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
la variable est dèja active ! mais ca n'affiche rien
merci
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 12h20   #6
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
hmmm je viens de lire ceci sur php.ini :

Citation:
Output buffering is a mechanism for controlling how much output data
; (excluding headers and cookies) PHP should keep internally before pushing that
; data to the client. If your application's output exceeds this setting, PHP
; will send that data in chunks of roughly the size you specify.
; Turning on this setting and managing its maximum buffer size can yield some
; interesting side-effects depending on your application and web server.
; You may be able to send headers and cookies after you've already sent output
; through print or echo.
You also may see performance benefits if your server is
; emitting less packets due to buffered output versus PHP streaming the output
; as it gets it.
es ce que ca veux dire que même sans buffering je peux mettre des echo et print avant un header() ou pas ?
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 13h14   #7
Membre éprouvé
 
Homme romain escudier
Développeur informatique
Inscription : juin 2011
Messages : 300
Détails du profil
Informations personnelles :
Nom : Homme romain escudier
Âge : 22
Localisation : France, Ille et Vilaine (Bretagne)

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2011
Messages : 300
Points : 471
Points : 471
Oui tu peux mettre des echo et print avant un header

Citation:
Warning: Cannot modify header information - headers already sent by (output started at xxxxxxx ...
veut dire que tu as deja modifier le header par exemple quand tu enchaine 2 header de suite or echo et print ne modifient pas le header
__________________
Pas de solution, pas de probleme

Une réponse utile (ou +1) le pouce vert
Une réponse à votre question

skeud est déconnecté   Envoyer un message privé Réponse avec citation 02
Vieux 15/06/2011, 13h29   #8
Modérateur
 
Inscription : septembre 2010
Messages : 7 103
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 103
Points : 8 466
Points : 8 466
Citation:
Envoyé par Benjamin Delespierre Voir le message
Mets l'error reporting au max et l'erreur devrait se montrer

Code :
1
2
3
4
<?php
error_reporting(E_ALL | E_DEPRECATED | E_USER_NOTICE | E_NOTICE);
ini_set('display_errors', 1);
?>
tu peux mettre l'erreur au max avec
de plus ca marche avec toutes les versions de PHP
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 50
Vieux 15/06/2011, 13h53   #9
Modérateur
 
Avatar de Benjamin Delespierre
 
Benjamin Delespierre
Développeur Web
Inscription : février 2010
Messages : 2 984
Détails du profil
Informations personnelles :
Nom : Benjamin Delespierre
Âge : 24
Localisation : France

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : février 2010
Messages : 2 984
Points : 5 016
Points : 5 016
@stealth Je l'ignorais, merci pour l'info
__________________
A la recherche d'un framework MVC facile a prendre en main ? Essayez Axiom
Nouveau: la référence d'Axiom est disponible sur GitHub (je la peaufine en ce moment même).

Un problème correctement identifié est à moitié résolu, évitez de poster l'intégralité de votre code avec pour seule explication "ça ne marche pas...".
Pour identifier correctement vos problèmes PHP, utilisez la gestion des erreurs et xdebug.

Les boutons et existent, servez-vous en
Benjamin Delespierre est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 14h47   #10
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
Et ben je n'arrive pas à comprendre pourquoi ca m'affiche l'erreur dans mon code

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
 
 
<?php
session_start();
include "class/dbcnx.class.php";
 
function homie()
{
if ($_SESSION['role']== "administrateur")
	{
	echo "<a href=\"adminfunct.php\"></a>";
	}
if ($_SESSION['role']== "employe")
	{
	echo "<a href=\"empl_home.php\"></a>";
	}	
if ($_SESSION['role']== "ag_gest")
	{
	echo "<a href=\"index_agent_home.php\"></a>";
	}
}
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
<meta name="keywords" content="free css templates, blue ice, CSS, HTML, templatemo" />
<meta name="description" content="Blue Ice is one of the Free CSS Templates from templatemo.com" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />
 
</head>
<body>
 
<div id="templatemo_wrapper">
<!-- end of templatemo_header -->
 
<div id="templatemo_menu">
    	<div class="home"><?php homie() ;?></div>
        <ul>
         <?php if ($_SESSION['role']== "administrateur") { echo " 
		    <li><a href=\"view_veh2.php\"><span>Gerer les vehicules</span></a></li>
            <li><a href=\"ins_user.php\"><span>G&eacute;rer les utilisateurs</span></a></li>
            <li><a href=\"ins_sinistre.php\"><span>G&eacute;rer les sinistres</span></a></li>
            <li><a href=\"add_mission.php\"><span>G&eacute;rer les missions</span></a></li>
            <li><a href=\"intervention.php\"><span>G&eacute;rer les interventions</span></a></li>
            <li><a href=\"decl_panne.php\"><span>G&eacute;rer pannes</span></a></li>
            <li><a href=\"carburant_man.php\"><span>G&eacute;rer carburants</span></a></li>
            <li><a href=\"assu_man.php\"><span>G&eacute;rer assurances</span></a></li>
            <li><a href=\"tab_bord.php\"><span>Tableau de bord</span></a></li> "; } 
			if ($_SESSION['role']== "ag_gest"){ echo " 
		    <li><a href=\"view_veh2.php\"><span>Gerer les vehicules</span></a></li>
            <li><a href=\"ins_empl2.php\"><span>G&eacute;rer les employés</span></a></li>
            <li><a href=\"ins_sinistre.php\"><span>G&eacute;rer les sinistres</span></a></li>
            <li><a href=\"add_mission.php\"><span>G&eacute;rer les missions</span></a></li>
            <li><a href=\"intervention.php\"><span>G&eacute;rer les interventions</span></a></li>
            <li><a href=\"decl_panne.php\"><span>G&eacute;rer pannes</span></a></li>
            <li><a href=\"carburant_man.php\"><span>G&eacute;rer carburants</span></a></li>
            <li><a href=\"assu_man.php\"><span>G&eacute;rer assurances</span></a></li>"; } 
			if ($_SESSION['role']== "employe"){echo "
			<li><a href=\"ins_sinistre.php\"><span>G&eacute;rer les sinistres</span></a></li>
            <li><a href=\"add_mission.php\"><span>G&eacute;rer les missions</span></a></li>
            <li><a href=\"decl_panne.php\"><span>G&eacute;rer une panne</span></a></li> ";}
			?>
        </ul>    	
    </div> <!-- end of templatemo_menu -->
 
    <div id="templatemo_content_wrapper">
 
<div id="templatemo_content_top"> </div>
 
        <div id="templatemo_content">
<table width="1000" border="0">
<tr><td align="right"><a href="index.php"><span>Déconnexion</span></a></td></tr>
</table>
<?php
if ($_GET['action'] == "del")
{
$mat = $_GET['matricule'];
$dbcnx = new dbcnx();
$dbcnx->cnx("localhost","root","","baseparcauto");
$query= "DELETE  FROM `missions`  where `numMission` = '$mat'";
$req1 = mysql_query($query) or die (mysql_error());
if ($req1) {echo "Suppression réussie !"; header("location: view_empl_mission.php");}
}
if ($_GET['action'] == "modif")
{
$mat = $_GET['matricule'];
$dbcnx = new dbcnx();
$dbcnx->cnx("localhost","root","","baseparcauto");
$query= "SELECT * FROM `missions`  where `numMission` like '$mat'";
$req1 = mysql_query($query) or die (mysql_error());
$res = mysql_fetch_array($req1);
?>
<h2>Merci d'appliquer vos modifications!</h2>
<table width="450" border="0">
<form id="form1" name="form1" method="post" action="">
  <tr>
    <td width="228">Immatriculation du Vehicule</td>
    <td width="39">&nbsp;</td>
    <td width="169"><input type="text" name="mission_immatriculation_veh" id="mission_immatriculation_veh" value="<?php echo $res['immatriculation_veh']; ?>"/></td>
  </tr>
  <tr>
    <td>Date départ</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_dateDepart" id="mission_dateDepart" value="<?php echo $res['dateDepart']; ?>"/></td>
  </tr>
  <tr>
    <td>Heure départ</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_heurDepart" id="mission_heurDepart" value="<?php echo $res['heurDepart']; ?>"/></td>
  </tr>
  <tr>
    <td>Date arrivée</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_dateArrivee" id="mission_dateArrivee" value="<?php echo $res['dateArrivee']; ?>"/></td>
  </tr>
  <tr>
    <td>Heure arrivée</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_heurArrivee" id="mission_heurArrivee" value="<?php echo $res['heurArrivee']; ?>"/></td>
  </tr>
  <tr>
    <td>Objectif</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_objectif" id="mission_objectif" value="<?php echo $res['objectif']; ?>"/></td>
  </tr>
  <tr>
    <td>Kilometrage départ</td>
    <td>&nbsp;</td>
    <td><input type="text"name="mission_kilometrageDeDepart"id="mission_kilometrageDeDepart"value="<?php echo $res['kilometrageDeDepart']; ?>"/></td>
  </tr>
  <tr>
    <td>Kilometrage arrivée</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_kilometrageD_arrivee" id="mission_kilometrageD_arrivee" value="<?php echo $res['kilometrageD_arrivee']; ?>"/></td>
  </tr>
  <tr>
    <td>Lieu départ</td>
    <td></td>
    <td><input type="text"name="mission_lieuDepart"id="mission_lieuDepart"value="<?php echo $res['lieuDepart']; ?>"/></td>
  </tr>
  <tr>
    <td>Destination</td>
    <td>&nbsp;</td>
    <td><input type="text"name="mission_destination"id="mission_destination"value="<?php echo $res['destination']; ?>"/></td>
  </tr>
  <tr>
    <td>Etat objectif</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_etat_objectif" id="mission_etat_objectif" value="<?php echo $res['etat_objectif']; ?>" /></td>
  </tr>
<tr>
    <td><input type="submit" name="ins_mission_btn" id="ins_mission_btn" value="Modifier" /></td>
    <td></td>
    <td></td>
  </tr>
</form>
</table>
<?php
if (isset($_POST['ins_mission_btn']))
{
$d = date("y-m-d h:i:s" );
$toverif = array($_POST['mission_immatriculation_veh'],$_POST['mission_dateDepart'],$_POST['mission_heurDepart'],$_POST['mission_dateArrivee'],$_POST['mission_heurArrivee'],$_POST['mission_objectif'],$_POST['mission_kilometrageDeDepart'],$_POST['mission_kilometrageD_arrivee'],$_POST['mission_lieuDepart'],$_POST['mission_destination'],$_POST['mission_etat_objectif'],$d);
$arr = $dbcnx->fetchArray($dbcnx->query($query),$toverif);
				 $z = implode ("','",$toverif);
				 $z.="'";
				 $s = "'".$z ;
				$query= "UPDATE `missions` SET `immatriculation_veh` = '$toverif[0]'  ,`dateDepart` = '$toverif[1]',`heurDepart` = '$toverif[2]',`dateArrivee` = '$toverif[3]' ,`heurArrivee` = '$toverif[4]',`objectif` = '$toverif[5]',`kilometrageDeDepart` = '$toverif[6]',`kilometrageD_arrivee` = '$toverif[7]',`lieuDepart` = '$toverif[8]',`destination` = '$toverif[9]',`etat_objectif` = '$toverif[10]',`date_last_modif` = '$toverif[11]' WHERE `missions`.`numMission` = '$mat' ";
$res = mysql_query ($query) or die (mysql_error());
if($res = true) {
echo "Informations modifiés avec succes ! ";
//echo "<a href= view_empl_mission.php>retour</a>";
header("location:view_empl_mission.php");
}
}
}
?>
<?php
function FindVeh ()
{
$con1= "<option value=\"";
$i = 0;
$arr_opt = array();
$veh_arr = array();
$dbcnx = new dbcnx();
$dbcnx->cnx("localhost","root","","baseparcauto");
$query= "SELECT `immatriculation` FROM `veh` ";
$req = mysql_query ($query) or die (mysql_error());
while ($res = mysql_fetch_array($req))
	{
	array_push($veh_arr,$res['immatriculation']);
	}
$str_veh = implode (",",$veh_arr);
	foreach($veh_arr as $opt)
	{
	$opt = "<option value=\"".$opt."\">".$opt."</option>";
	array_push($arr_opt,$opt);
	}
	$nbopt = count($arr_opt);
	echo "<select name=\"ins_interv_immatriculation\">"."\n";
	echo "<option value=\"\" selected=\"selected\"></option>";
	while($i <= $nbopt-1)
	{
	echo $arr_opt[$i]."\n";
	$i++;
	}
	echo "</select>";
}
?>
   </div>
        <div id="templatemo_content_bottom"></div>
	</div>
</body>
</html>
l'erreur est

Citation:
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\EasyPHP-5.3.5.0\www\parkmanager\admin\modif_mission.php:171) in C:\Program Files\EasyPHP-5.3.5.0\www\parkmanager\admin\modif_mission.php on line 173
alors que dans un autre code :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
</head>
 
<body>
<h1>Salut !</h1>
<?php
$a = 1 ; 
if ($a == 1)
{
header("Location: page.php");
}
else 
{
echo "<h1>Salut !</h1>";
header("Location: page.php");
}
?>
 
</body>
</html>
la redirection marche ok!

je ne peux rien dire que Moooooooooooooooohhhhhh pour le moment
merci pour tout !
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 14h53   #11
Modérateur
 
Inscription : septembre 2010
Messages : 7 103
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 103
Points : 8 466
Points : 8 466
tu peux pas lancer un header si y'a deja du texte avant
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/06/2011, 11h05   #12
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
Bonjour tout le monde,

à stealth35 :

ce que je ne comprends pas est que dans le premier code seulement quand je supprime la ligne 173
Code :
echo "Informations modifiés avec succes ! ";
que la redirection passe

alors que dans le deuxième code de test malgré la presence de la ligne 19 avant le header
Code :
echo "<h1>Salut !</h1>";
la redirection passe sans problèmes

encore moooohhhh

merci d'avance .
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2011, 10h35   #13
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
bonjour tout le monde,

ou sont les gurus !!
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2011, 10h49   #14
Modérateur
 
Inscription : septembre 2010
Messages : 7 103
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 103
Points : 8 466
Points : 8 466
je vois pas ce que tu comprends pas, tu ne peux pas inséré un header si du texte a deja été envoyé a la sortie

remontre tes nouveaux codes et dis ou ça ne marche pas
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2011, 11h20   #15
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
Bonjour
salut stealth35,

j'ai lu maintes fois que je ne peux pas envoyer un header et en même temps avant afficher du texte avec echo ou print.

comme je t ai dit avant

dans mon code d'un page de modification d'infos :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
 
<?php
session_start();
include "class/dbcnx.class.php";
 
function homie()
{
if ($_SESSION['role']== "administrateur")
	{
	echo "<a href=\"adminfunct.php\"></a>";
	}
if ($_SESSION['role']== "employe")
	{
	echo "<a href=\"empl_home.php\"></a>";
	}	
if ($_SESSION['role']== "ag_gest")
	{
	echo "<a href=\"index_agent_home.php\"></a>";
	}
}
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
<meta name="keywords" content="free css templates, blue ice, CSS, HTML, templatemo" />
<meta name="description" content="Blue Ice is one of the Free CSS Templates from templatemo.com" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />
 
</head>
<body>
 
<div id="templatemo_wrapper">
<!-- end of templatemo_header -->
 
<div id="templatemo_menu">
    	<div class="home"><?php homie() ;?></div>
        <ul>
         <?php if ($_SESSION['role']== "administrateur") { echo " 
		    <li><a href=\"view_veh2.php\"><span>Gerer les vehicules</span></a></li>
            <li><a href=\"ins_user.php\"><span>G&eacute;rer les utilisateurs</span></a></li>
            <li><a href=\"ins_sinistre.php\"><span>G&eacute;rer les sinistres</span></a></li>
            <li><a href=\"add_mission.php\"><span>G&eacute;rer les missions</span></a></li>
            <li><a href=\"intervention.php\"><span>G&eacute;rer les interventions</span></a></li>
            <li><a href=\"decl_panne.php\"><span>G&eacute;rer pannes</span></a></li>
            <li><a href=\"carburant_man.php\"><span>G&eacute;rer carburants</span></a></li>
            <li><a href=\"assu_man.php\"><span>G&eacute;rer assurances</span></a></li>
            <li><a href=\"tab_bord.php\"><span>Tableau de bord</span></a></li> "; } 
			if ($_SESSION['role']== "ag_gest"){ echo " 
		    <li><a href=\"view_veh2.php\"><span>Gerer les vehicules</span></a></li>
            <li><a href=\"ins_empl2.php\"><span>G&eacute;rer les employés</span></a></li>
            <li><a href=\"ins_sinistre.php\"><span>G&eacute;rer les sinistres</span></a></li>
            <li><a href=\"add_mission.php\"><span>G&eacute;rer les missions</span></a></li>
            <li><a href=\"intervention.php\"><span>G&eacute;rer les interventions</span></a></li>
            <li><a href=\"decl_panne.php\"><span>G&eacute;rer pannes</span></a></li>
            <li><a href=\"carburant_man.php\"><span>G&eacute;rer carburants</span></a></li>
            <li><a href=\"assu_man.php\"><span>G&eacute;rer assurances</span></a></li>"; } 
			if ($_SESSION['role']== "employe"){echo "
			<li><a href=\"ins_sinistre.php\"><span>G&eacute;rer les sinistres</span></a></li>
            <li><a href=\"add_mission.php\"><span>G&eacute;rer les missions</span></a></li>
            <li><a href=\"decl_panne.php\"><span>G&eacute;rer une panne</span></a></li> ";}
			?>
        </ul>    	
    </div> <!-- end of templatemo_menu -->
 
    <div id="templatemo_content_wrapper">
 
<div id="templatemo_content_top"> </div>
 
        <div id="templatemo_content">
<table width="1000" border="0">
<tr><td align="right"><a href="index.php"><span>Déconnexion</span></a></td></tr>
</table>
<?php
if ($_GET['action'] == "del")
{
$mat = $_GET['matricule'];
$dbcnx = new dbcnx();
$dbcnx->cnx("localhost","root","","baseparcauto");
$query= "DELETE  FROM `missions`  where `numMission` = '$mat'";
$req1 = mysql_query($query) or die (mysql_error());
if ($req1) {
echo "Suppression réussie !";
header("location: view_empl_mission.php");
}
}
if ($_GET['action'] == "modif")
{
$mat = $_GET['matricule'];
$dbcnx = new dbcnx();
$dbcnx->cnx("localhost","root","","baseparcauto");
$query= "SELECT * FROM `missions`  where `numMission` like '$mat'";
$req1 = mysql_query($query) or die (mysql_error());
$res = mysql_fetch_array($req1);
?>
<h2>Merci d'appliquer vos modifications!</h2>
<table width="450" border="0">
<form id="form1" name="form1" method="post" action="">
  <tr>
    <td width="228">Immatriculation du Vehicule</td>
    <td width="39">&nbsp;</td>
    <td width="169"><input type="text" name="mission_immatriculation_veh" id="mission_immatriculation_veh" value="<?php echo $res['immatriculation_veh']; ?>"/></td>
  </tr>
  <tr>
    <td>Date départ</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_dateDepart" id="mission_dateDepart" value="<?php echo $res['dateDepart']; ?>"/></td>
  </tr>
  <tr>
    <td>Heure départ</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_heurDepart" id="mission_heurDepart" value="<?php echo $res['heurDepart']; ?>"/></td>
  </tr>
  <tr>
    <td>Date arrivée</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_dateArrivee" id="mission_dateArrivee" value="<?php echo $res['dateArrivee']; ?>"/></td>
  </tr>
  <tr>
    <td>Heure arrivée</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_heurArrivee" id="mission_heurArrivee" value="<?php echo $res['heurArrivee']; ?>"/></td>
  </tr>
  <tr>
    <td>Objectif</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_objectif" id="mission_objectif" value="<?php echo $res['objectif']; ?>"/></td>
  </tr>
  <tr>
    <td>Kilometrage départ</td>
    <td>&nbsp;</td>
    <td><input type="text"name="mission_kilometrageDeDepart"id="mission_kilometrageDeDepart"value="<?php echo $res['kilometrageDeDepart']; ?>"/></td>
  </tr>
  <tr>
    <td>Kilometrage arrivée</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_kilometrageD_arrivee" id="mission_kilometrageD_arrivee" value="<?php echo $res['kilometrageD_arrivee']; ?>"/></td>
  </tr>
  <tr>
    <td>Lieu départ</td>
    <td></td>
    <td><input type="text"name="mission_lieuDepart"id="mission_lieuDepart"value="<?php echo $res['lieuDepart']; ?>"/></td>
  </tr>
  <tr>
    <td>Destination</td>
    <td>&nbsp;</td>
    <td><input type="text"name="mission_destination"id="mission_destination"value="<?php echo $res['destination']; ?>"/></td>
  </tr>
  <tr>
    <td>Etat objectif</td>
    <td>&nbsp;</td>
    <td><input type="text" name="mission_etat_objectif" id="mission_etat_objectif" value="<?php echo $res['etat_objectif']; ?>" /></td>
  </tr>
<tr>
    <td><input type="submit" name="ins_mission_btn" id="ins_mission_btn" value="Modifier" /></td>
    <td></td>
    <td></td>
  </tr>
</form>
</table>
<?php
if (isset($_POST['ins_mission_btn']))
{
$d = date("y-m-d h:i:s" );
$toverif = array($_POST['mission_immatriculation_veh'],$_POST['mission_dateDepart'],$_POST['mission_heurDepart'],$_POST['mission_dateArrivee'],$_POST['mission_heurArrivee'],$_POST['mission_objectif'],$_POST['mission_kilometrageDeDepart'],$_POST['mission_kilometrageD_arrivee'],$_POST['mission_lieuDepart'],$_POST['mission_destination'],$_POST['mission_etat_objectif'],$d);
$arr = $dbcnx->fetchArray($dbcnx->query($query),$toverif);
				 $z = implode ("','",$toverif);
				 $z.="'";
				 $s = "'".$z ;
				$query= "UPDATE `missions` SET `immatriculation_veh` = '$toverif[0]'  ,`dateDepart` = '$toverif[1]',`heurDepart` = '$toverif[2]',`dateArrivee` = '$toverif[3]' ,`heurArrivee` = '$toverif[4]',`objectif` = '$toverif[5]',`kilometrageDeDepart` = '$toverif[6]',`kilometrageD_arrivee` = '$toverif[7]',`lieuDepart` = '$toverif[8]',`destination` = '$toverif[9]',`etat_objectif` = '$toverif[10]',`date_last_modif` = '$toverif[11]' WHERE `missions`.`numMission` = '$mat' ";
$res = mysql_query ($query) or die (mysql_error());
if($res = true) {
echo "Informations modifiés avec succes ! ";
//echo "<a href= view_empl_mission.php>retour</a>";
header("location:view_empl_mission.php");
//if (headers_sent($file,$line))
//{
//echo "h sent in ".$file." on line ".$line;
//var_dump(headers_list());
//}
}
}
}
function FindVeh ()
{
$con1= "<option value=\"";
$i = 0;
$arr_opt = array();
$veh_arr = array();
$dbcnx = new dbcnx();
$dbcnx->cnx("localhost","root","","baseparcauto");
$query= "SELECT `immatriculation` FROM `veh` ";
$req = mysql_query ($query) or die (mysql_error());
while ($res = mysql_fetch_array($req))
	{
	array_push($veh_arr,$res['immatriculation']);
	}
$str_veh = implode (",",$veh_arr);
	foreach($veh_arr as $opt)
	{
	$opt = "<option value=\"".$opt."\">".$opt."</option>";
	array_push($arr_opt,$opt);
	}
	$nbopt = count($arr_opt);
	echo "<select name=\"ins_interv_immatriculation\">"."\n";
	echo "<option value=\"\" selected=\"selected\"></option>";
	while($i <= $nbopt-1)
	{
	echo $arr_opt[$i]."\n";
	$i++;
	}
	echo "</select>";
}
?>
</div>
        <div id="templatemo_content_bottom"></div>
	</div>
</body>
</html>
tout va bien mais la redirection ne passe pas sauf si j'applique la regle et je supprime la ligne 174 qui est :
Code :
echo "Informations modifiés avec succes ! ";
cool mais

ce que je ne comprends pas est que dans le code de test suivant :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
</head>
 
<body>
<h1>Salut !</h1>
<?php
$a = 1 ; 
if ($a == 1)
{
header("Location: page.php");
//if (headers_sent($file,$line))
//{
//echo "h sent in ".$file." on line ".$line;
//}
}
else 
{
echo "<h1>Salut !</h1>";
header("Location: page.php");
//if (headers_sent($file,$line))
//{
//echo "h sent in ".$file." on line ".$line;
//var_dump(headers_list());
//}
}
?>
 
</body>
</html>
la redirection passe avec succès malgré que la règle des headers n'est pas appliquée car j'affiche du texte juste avant le header à la ligne 22 :
Code :
echo "<h1>Salut !</h1>";
alors pourquoi le message

Citation:
Warning: Cannot modify header information - headers already sent by (output started at ...)
ne s'affiche pas ici dans la page de test !!

j'ai en plus laissé une ligne vide après la balise de fin de php pais pas d'erreurs aussi !!!!

j'espère que j'étais clair .
merci d'avance
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2011, 11h33   #16
Modérateur
 
Inscription : septembre 2010
Messages : 7 103
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 103
Points : 8 466
Points : 8 466
a quelle valeur est ton output_buffering (dans ton phpinfo) ?
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2011, 11h44   #17
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
salut

output_buffering 4096 4096

es ce que je dois comprendre que même si j'utilise pas le buffering explicitement dans mon code , si la valeur de sortie est moins que celle de output_buffering 4096 , php ne fais pas de message d'erreur ! et que le buffering est automatique ?

merci stealth35 !
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2011, 11h45   #18
Modérateur
 
Inscription : septembre 2010
Messages : 7 103
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 103
Points : 8 466
Points : 8 466
Citation:
Envoyé par el_bacha Voir le message
salut

output_buffering 4096 4096

es ce que je dois comprendre que même si j'utilise pas le buffering explicitement dans mon code , si la valeur de sortie est moins que celle de output_buffering 4096 , php ne fais pas de message d'erreur ! et que le buffering est automatique ?

merci stealth35 !
t'as tout compris,
je te conseil de mettre cette valeur à 0
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2011, 11h56   #19
Invité de passage
 
Homme
Développeur informatique
Inscription : avril 2011
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Développeur informatique
Secteur : Enseignement

Informations forums :
Inscription : avril 2011
Messages : 15
Points : 2
Points : 2
ah super !!

merci stealth35

tu ma éclairé la lanterne !!

donc il ne me reste que d'utiliser le buffering la prochaine fois si j'aurais a afficher n'importe quoi dans une page qui contient un header() .

mille merci encore .

résolu.
el_bacha est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 21h09.


 
 
 
 
Partenaires

Hébergement Web