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 :

Cannot modify header information - headers already sent


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    97
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 97
    Points : 49
    Points
    49
    Par défaut Cannot modify header information - headers already sent
    Bonjour,

    Je sais que beaucoup de messages sont postés sur le sujet (j'en ai déjà lus pas mal, sans pour autant réussir à solutionner mon problème).

    Quand un nouveau client s'inscrit sur mon site, la validation du formulaire enregistre correctement toutes les données dans la base par contre, au lieu d'ouvrir la page vers laquelle il devrait être redirigé, le client se retrouve devant le formulaire d'inscription (vide) qu'il vient de remplir et il y a l'erreur suivante qui s'affiche :
    Warning: Cannot modify header information - headers already sent by (output started at /wxxx/inscription.php:5) in /xxx/inscription.php on line 83

    Voici la ligne 83 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    header(sprintf("Location: %s", $insertGoTo));
    J'utilise cette ligne de code dans d'autres fichiers (ex : ajout fiche produit) et ça fonctionne. Je n'arrive pas à voir la différence...

    Voici tout ce qui se trouve avant mon doctype :
    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
    <?php 
    session_start(); 
    ?>
    
    <?php require_once('../Connections/xxx.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    // Redirect if username exists
    $MM_flag="MM_insert";
    if (isset($_POST[$MM_flag])) {
      $MM_dupKeyRedirect="inscription.php";
      $loginUsername = $_POST['mail'];
      $LoginRS__query = sprintf("SELECT mail FROM client WHERE mail=%s", GetSQLValueString($loginUsername, "text"));
      mysql_select_db($database_xxx, $xxx);
      $LoginRS=mysql_query($LoginRS__query, $xxx) or die(mysql_error());
      $loginFoundUser = mysql_num_rows($LoginRS);
    
      //if there is a row in the database, the username was found - can not add the requested username
      if($loginFoundUser){
        $MM_qsChar = "?";
        //append the username to the redirect page
        if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
        $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
        header ("Location: $MM_dupKeyRedirect");
        exit;
      }
    }
    
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "client")) {
      $insertSQL = sprintf("INSERT INTO client (nom, prenom, mot_passe, adresse1, cp, ville, mail, tel) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['nom'], "text"),
                           GetSQLValueString($_POST['prenom'], "text"),
                           GetSQLValueString($_POST['mot_passe'], "text"),
                           GetSQLValueString($_POST['adresse1'], "text"),
                           GetSQLValueString($_POST['cp'], "int"),
                           GetSQLValueString($_POST['ville'], "text"),
                           GetSQLValueString($_POST['mail'], "text"),
                           GetSQLValueString($_POST['tel'], "text"));
    
      mysql_select_db($database_xxx, $xxx);
      $Result1 = mysql_query($insertSQL, $xxx) or die(mysql_error());
    
      $insertGoTo = "inscription_conf.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
     
    }
    ?>
    J'espère que quelqu'un pourra m'expliquer comment pallier cette erreur.

  2. #2
    Membre éclairé Avatar de micetf
    Homme Profil pro
    Professeur des Ecoles
    Inscrit en
    Mai 2009
    Messages
    557
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ardèche (Rhône Alpes)

    Informations professionnelles :
    Activité : Professeur des Ecoles
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2009
    Messages : 557
    Points : 831
    Points
    831
    Par défaut
    Bonsoir,

    Peut-être qu'en ne faisant qu'un seul bloc PHP ?
    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
    <?php 
    session_start();
    require_once('../Connections/xxx.php');
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }
     
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
     
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
     
    // Redirect if username exists
    $MM_flag="MM_insert";
    if (isset($_POST[$MM_flag])) {
      $MM_dupKeyRedirect="inscription.php";
      $loginUsername = $_POST['mail'];
      $LoginRS__query = sprintf("SELECT mail FROM client WHERE mail=%s", GetSQLValueString($loginUsername, "text"));
      mysql_select_db($database_xxx, $xxx);
      $LoginRS=mysql_query($LoginRS__query, $xxx) or die(mysql_error());
      $loginFoundUser = mysql_num_rows($LoginRS);
     
      //if there is a row in the database, the username was found - can not add the requested username
      if($loginFoundUser){
        $MM_qsChar = "?";
        //append the username to the redirect page
        if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
        $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
        header ("Location: $MM_dupKeyRedirect");
        exit;
      }
    }
     
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
     
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "client")) {
      $insertSQL = sprintf("INSERT INTO client (nom, prenom, mot_passe, adresse1, cp, ville, mail, tel) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['nom'], "text"),
                           GetSQLValueString($_POST['prenom'], "text"),
                           GetSQLValueString($_POST['mot_passe'], "text"),
                           GetSQLValueString($_POST['adresse1'], "text"),
                           GetSQLValueString($_POST['cp'], "int"),
                           GetSQLValueString($_POST['ville'], "text"),
                           GetSQLValueString($_POST['mail'], "text"),
                           GetSQLValueString($_POST['tel'], "text"));
     
      mysql_select_db($database_xxx, $xxx);
      $Result1 = mysql_query($insertSQL, $xxx) or die(mysql_error());
     
      $insertGoTo = "inscription_conf.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
     
    }
    ?>
    Fred

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    97
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 97
    Points : 49
    Points
    49
    Par défaut
    C'est ça. Merci beaucoup !

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

Discussions similaires

  1. Réponses: 2
    Dernier message: 09/02/2010, 20h32
  2. Réponses: 3
    Dernier message: 04/10/2009, 14h15
  3. Réponses: 1
    Dernier message: 17/07/2007, 11h49
  4. Réponses: 4
    Dernier message: 16/07/2007, 13h42
  5. Réponses: 5
    Dernier message: 04/09/2006, 15h13

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