Version complète: sur le forum Webmaster Hub : Probléme avec php, les header
Webmaster Hub > Création et exploitation de Sites Internet > Les langages du Net > PHP
crocxx
Voila j'ai un probléme avec php, et la je suis vraimen coincé
CITATION
<?php
if (strstr($_SERVER['HTTP_ACCEPT '], 'application/xhtml+xml')) {
_AT_header('Content-type: application/xhtml+xml; charset = UTF-8 ');
}
else {
_AT_header('Content-type: text/html; charset = UTF-8 ');
}
if (!isset($_GET["p"])){
  $p = 'accueil';
}
else {
  if (file_exists("pages/$p.inc")){
    $p = $_GET["p"];
  }
  else {
    _AT_header("HTTP/1.0 404 Not Found");
  }
}
require "pages.php";

if (strstr($_SERVER['HTTP_ACCEPT '], 'application/xhtml+xml')) {
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
}

else {
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
}

?>



J'optien une erreur pour chaque header de ce code (avant de rajouté les @)
Les navigateur acceptant application/xhtml+xml m'affiche:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd


Je suis heberger sous OVH peu étre que ça vien de la???

Ce code php et le premier sur la page, pas d'espace avant pas d'espaces aprés.


Merci pour votre aide, jéspére. wink.gif
NorSeb
Bonjour,

CITATION(crocxx @ samedi 24 décembre 2005, 12h03)
J'optien une erreur pour chaque header de ce code (avant de rajouté les @)


Qu'obtiens-tu si enlève les @ ?
crocxx
Warning: Cannot modify header information - headers already sent by (output started at /home.2/zonewebm/www/ZW2/index.php:1) in /home.2/zonewebm/www/ZW2/index.php on line 6

Sous internet exploreur et mozilla
ça aussi c'est anormal sa veux dir que la ligne:
CODE
if (strstr($_SERVER['HTTP_ACCEPT '], 'application/xhtml+xml')) {

n'est pas bonne non plus
Sinon sa me donnerait line 6 et line 4 non???

Quand la varriable $p est egalle a un fichier non existant:
CODE
 if (file_exists("pages/$p.inc")){
   $p = $_GET["p"];
 }
 else {
   header("HTTP/1.0 404 Not Found");
 }


sa me donne cette erreur en plus:

CODE
Warning: Cannot modify header information - headers already sent by (output started at /home.2/zonewebm/www/ZW2/index.php:1) in /home.2/zonewebm/www/ZW2/index.php on line 16


C'est bizard on dirait ques les header ne sont par reconu pourtant il n'y a rien avant ce code php sur ma page. pas d'espace pas d'echo
Chark
Les headers sont tres "pointilleux" sur certaines regles à respecter:

Aucun espace dans ton code avant le header
Aucune ligne affiché ( "echo" ou autre ) avant le header !!! ( il suffit par exemple que tu mette une ligne "vous allez etre redirigé dans quelques secondes" pour que ton header renvoie une erreur)

reverifie ton code en entier et veille à respecter ces regles pour voir...
Anonymus
Tu envoies ces lignes :
CODE
if (strstr($_SERVER['HTTP_ACCEPT '], 'application/xhtml+xml')) {
_AT_header('Content-type: application/xhtml+xml; charset = UTF-8 ');
}
else {
_AT_header('Content-type: text/html; charset = UTF-8 ');
}

puis tu demandes à faire une redirection.

Il ne peut la faire, puisqu'il a envoyé ces lignes, donc il a déjà envoyé quelque chose. cqfd.


Pour ces lignes :
CODE
if (strstr($_SERVER['HTTP_ACCEPT '], 'application/xhtml+xml')) {
_AT_header('Content-type: application/xhtml+xml; charset = UTF-8 ');
}
else {
_AT_header('Content-type: text/html; charset = UTF-8 ');
}
if (!isset($_GET["p"])){
 $p = 'accueil';
}
else {
 if (file_exists("pages/$p.inc")){
   $p = $_GET["p"];
 }
 else {
   @header("HTTP/1.0 404 Not Found");
 }
}

Tu aurais du les mettre dans l'ordre inverse :
CODE
if (!isset($_GET["p"])){
 $p = 'accueil';
}
else {
 if (file_exists("pages/$p.inc")){
   $p = $_GET["p"];
 }
 else {
   @header("HTTP/1.0 404 Not Found");
 }
}

if (strstr($_SERVER['HTTP_ACCEPT '], 'application/xhtml+xml')) {
_AT_header('Content-type: application/xhtml+xml; charset = UTF-8 ');
}
else {
_AT_header('Content-type: text/html; charset = UTF-8 ');
}


ps :
Pour info, tu devrais appeler tes fichiers : fichier.inc.php et non .inc seulement.
Ainsi, ils ne peuvent être lus.
Ceci est une version "bas débit" de notre forum. Pour voir la version complète avec plus d'information, la mise en page et les images, veuillez cliquer ici.