IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

bizarre pas de warning pour ceci ? output avant header sans bufferisation [PHP 5.3]


Sujet :

Langage PHP

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut bizarre pas de warning pour ceci ? output avant header sans bufferisation
    bonjour tout le monde,

    regardez ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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

    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

  2. #2
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

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

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    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) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  3. #3
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    Pardon ! je ne comprends pas !
    pouvez vous expliquer ?
    merci

  4. #4
    Expert éminent
    Avatar de Benjamin Delespierre
    Profil pro
    Développeur Web
    Inscrit en
    Février 2010
    Messages
    3 929
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

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

    Informations forums :
    Inscription : Février 2010
    Messages : 3 929
    Points : 7 762
    Points
    7 762
    Par défaut
    Mets l'error reporting au max et l'erreur devrait se montrer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <?php
    error_reporting(E_ALL | E_DEPRECATED | E_USER_NOTICE | E_NOTICE);
    ini_set('display_errors', 1);
    ?>

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    la variable est dèja active ! mais ca n'affiche rien
    merci

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    hmmm je viens de lire ceci sur php.ini :

    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 ?

  7. #7
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

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

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    Oui tu peux mettre des echo et print avant un header

    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) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  8. #8
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    Citation Envoyé par Benjamin Delespierre Voir le message
    Mets l'error reporting au max et l'erreur devrait se montrer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  9. #9
    Expert éminent
    Avatar de Benjamin Delespierre
    Profil pro
    Développeur Web
    Inscrit en
    Février 2010
    Messages
    3 929
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

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

    Informations forums :
    Inscription : Février 2010
    Messages : 3 929
    Points : 7 762
    Points
    7 762
    Par défaut
    @stealth Je l'ignorais, merci pour l'info

  10. #10
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    Et ben je n'arrive pas à comprendre pourquoi ca m'affiche l'erreur dans mon code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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

    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 !

  11. #11
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    tu peux pas lancer un header si y'a deja du texte avant

  12. #12
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    echo "<h1>Salut !</h1>";
    la redirection passe sans problèmes

    encore moooohhhh

    merci d'avance .

  13. #13
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    bonjour tout le monde,

    ou sont les gurus !!

  14. #14
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    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

  15. #15
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    echo "Informations modifiés avec succes ! ";
    cool mais

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

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    echo "<h1>Salut !</h1>";
    alors pourquoi le message

    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

  16. #16
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    a quelle valeur est ton output_buffering (dans ton phpinfo) ?

  17. #17
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    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 !

  18. #18
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    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

  19. #19
    Futur Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    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 : 7
    Points
    7
    Par défaut
    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.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. pas d'erreur d'un echo avant header('location:)';
    Par __fabrice dans le forum Langage
    Réponses: 1
    Dernier message: 18/04/2008, 12h03
  2. Je ne trouve pas la requete pour modifier les entrées...
    Par guttts dans le forum Langage SQL
    Réponses: 7
    Dernier message: 24/08/2005, 19h17
  3. Pas de DNS pour les clients
    Par M.Dlb dans le forum Réseau
    Réponses: 2
    Dernier message: 05/07/2004, 23h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo