Page 1 sur 1

[phpBB] - Headers PHP capricieux...

Posté : 17 déc. 2013, 01:44
par casio
Salutations,

Nous utilisons sur la page d'accueil de notre site associatif un MOD récupéré sur phpbb-fr.com, mais ceux-ci ne veulent plus en entendre parler.
Il s'agit d'un plug-in phpBB qui affiche les 5 derniers posts de nos forums sur la home de notre site :
:arrow: http://wda-fr.org

Ce plug-in PHP est imbriqué en include sur l'accueil :

Code : Tout sélectionner

<?php // Session // $user->session_begin(); $auth->acl($user->data); $user->setup(); $forum_id = request_var('forum_id', 0); $sql = 'SELECT forum_id, topic_id, topic_time, topic_title, topic_views, topic_replies, topic_poster, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time FROM ' . TOPICS_TABLE . ' ORDER BY topic_last_post_time DESC'; if ( $forum_id ) { $sql = str_replace(TOPICS_TABLE, TOPICS_TABLE . ' WHERE forum_id = ' . (int) $forum_id, $sql); } $result = $db->sql_query_limit($sql, 5); echo '<table width="100%" class="newsforum">'; echo '<tr>'; echo '<th align="left">Sujets</th>'; echo '<th align="center">R&eacute;ponses</th>'; echo '<th align="center">Vus</th>'; echo '<th align="right">Dernier message</th>'; echo '</tr>'; while ( $row = $db->sql_fetchrow($result) ) { $row['topic_title'] = utf8_encode_ncr($row['topic_title']); $row['topic_first_poster_name'] = utf8_encode_ncr($row['topic_first_poster_name']); $row['topic_last_poster_name'] = utf8_encode_ncr($row['topic_last_poster_name']); $row['topic_time'] = $row['topic_time']; $row['topic_last_post_time'] = $row['topic_last_post_time']; $topic_id = (int) $row['topic_id']; $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . ($row['forum_id'] ? $row['forum_id'] : $forum_id) . '&t=' . $topic_id); echo '<tr>'; echo '<td align="left">'; echo '<a href="' . $view_topic_url . '" onclick="window.open(this.href); return false;">' . censor_text($row['topic_title']) . '</a><br />'; echo $user->lang['POST_BY_AUTHOR'] . '&nbsp;' . get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']); echo '&nbsp;' . $user->lang['POSTED_ON_DATE'] . '&nbsp;' . utf8_decode($user->format_date($row['topic_time'])) . '</td>'; echo '<td align="center">' . $row['topic_replies'] . '</td>'; echo '<td align="center">' . $row['topic_views'] . '</td>'; echo '<td align="right">' . $user->lang['POST_BY_AUTHOR'] . '&nbsp;' . get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']); echo '&nbsp;<a href="' . $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'] . '" onclick="window.open(this.href); return false;"><img src="' . $phpbb_root_path . 'styles/' . $user->theme['imageset_path'] . '/imageset/icon_topic_latest.gif" border="0" alt="' . $user->lang['VIEW_LATEST_POST'] . '" title="' . $user->lang['VIEW_LATEST_POST'] . '" />' . '</a><br />'; // Code WDA - echo '&nbsp;<a href="' . $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'] . '" target="_blank"><img src="' . $phpbb_root_path . 'styles/' . $user->theme['imageset_path'] . '/imageset/icon_topic_latest.gif" border="0" alt="' . $user->lang['VIEW_LATEST_POST'] . '" title="' . $user->lang['VIEW_LATEST_POST'] . '" />' . '</a><br />'; echo $user->lang['POSTED_ON_DATE'] . '&nbsp;' . utf8_decode($user->format_date($row['topic_last_post_time'])) . '</td>'; echo '</tr>'; } echo '</table>'; ?>
La page index.php de notre site (pas du forum, qui lui fonctionne très bien) :

Code : Tout sélectionner

<?php define('IN_PHPBB', true); // $phpbb_root_path = './forum/'; $phpbb_root_path = defined('PHPBB_ROOT_PATH') ? PHPBB_ROOT_PATH : './forum/'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include $phpbb_root_path . 'common.' . $phpEx; $user->session_begin(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html dir="ltr"> <?php $descriheader = "Association pour la preservation, la conservation et la restauration du patrimoine numerique. Premier musee virtuel Francophone de l'informatique & des jeux video, la WDA est une association a but non lucratif, regie par la loi du 1er juillet 1901. Fruit de la rencontre entre deux bidouilleurs de carcasses informatiques passionnes, l'association se veut aussi presente aupres des utilisateurs neophytes, en leurs apportant l'aide d'un forum de discussion, en mettant a leur disposition un espace de telechargements (freewares, emulateurs, drivers, etc.), un grand lexique, des fiches de procedures et d'assistance, un espace de destockage, des conseils materiels ou logiciels, tout en cherchant a retracer l'histoire du numerique !"; $menuhaut = "menuh.php"; $menugauche = "menug.php"; $pub = "pub.php"; (...) $rep = "./contenu"; $pageinc = "$rep/".$_GET[page].".php"; //test si page non vide mais fichier n'existe pas if (!file_exists($pageinc) && $_GET[page] != '') { $pageinc = "errors/404.php"; } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="fr-FR"> <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" l gen true for "http://wda-fr.org" r (nz 1 vz 1 lz 1 oz 1 ca 1 cb 1))'> <?php require_once './title.php'; ?> <title><?php echo $titre; ?></title> <meta name="robots" content="index,follow,all"> <meta name="rating" content="General"> <meta name="distribution" content="Global"> <meta name="Date-Creation-yyyymmdd" content="19971020"> <meta name="Date-Revision-yyyymmdd" content="20131124"> <meta name="revisit-after" content="7 days"> <?php require_once './descriheader.php'; ?> (...) <h2 align="left" id="pageName" class="atype2"><a href="http://forum.wda-fr.org/search.php?search_id=active_topics" target="_blank">Dernières contributions</a> sur <a href="http://forum.wda-fr.org" name="Forum" target="_blank">nos forums de discussions</a> :</h2> <div align="center"><?php include $news; ?></div> (...)
Il n'en reste pas moins que nous avons donc cette erreur en haut de l'include depuis environ 2 mois :
[phpBB Debug] PHP Warning: in file [ROOT]/includes/mobile.php on line 219: Cannot modify header information - headers already sent by (output started at /homepages/19/d179416033/htdocs/WDA/index.php:14)
Voici le code situé aux alentours de la ligne 219 de ce fichu theme pour mobile :

Code : Tout sélectionner

(...) /** * Set cookie value * * param string $value Cookie value * param bool $long If true, cookie will be set for full duration. If false, cookie will be set for browser session duration */ protected static function set_cookie($value, $long = true) { global $config; $cookietime = ($long && empty($_SERVER['HTTP_DNT'])) ? time() + (($config['max_autologin_time']) ? 86400 * (int) $config['max_autologin_time'] : 31536000) : 0; $name_data = rawurlencode(self::$cookie_var) . '=' . rawurlencode($value); $expire = ($cookietime) ? gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime) : ''; $domain = (!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']; header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $config['cookie_path'] . $domain . ((!$config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false); } (...)
Auriez-vous une idée ?

A vous lire,

Re: [phpBB] - Headers PHP capricieux...

Posté : 17 déc. 2013, 08:16
par xTG
Tu as une fonction header qui est utilisé alors que de l'affichage a déjà été effectuée avant.
header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $config['cookie_path'] . $domain . ((!$config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false);
Il faut que l'entête de la réponse HTTP soit remplie avant son contenu (le contenu étant le HTML).
Tu peux retarder l'affichage de ton code en utilisant la bufferisation (voir ob_start()).

Re: [phpBB] - Headers PHP capricieux...

Posté : 17 déc. 2013, 12:16
par casio
Merci de cette réponse.

Malheureusement, c'est complètement du chinois pour moi.

Concrètement ou dois-je et comment dois-je modifier ce/ces code(s) ?

Re: [phpBB] - Headers PHP capricieux...

Posté : 17 déc. 2013, 13:57
par xTG
Je ne peux pas te le dire sans connaître l'intégralité du code.
Chose qui ne se ferra pas en une minute, donc je n'ai pas le temps. :|

Re: [phpBB] - Headers PHP capricieux...

Posté : 17 déc. 2013, 15:05
par Mazarini
Bonjour,

Il y a de forte chance qu'un autre mod existe avec la même fonctionnalité. Si personne ne maintient celui que tu utilises, tu auras des problèmes lors de mises à jours et en plus ca veux dire qu'il n'y a pas de corrections de faille éventuelles.

Voilà comment tu peux modifier ta page d'accueil :
<?php
ob_start(); // ligne à ajouter
define('IN_PHPBB', true);
// $phpbb_root_path =  './forum/';
$phpbb_root_path = defined('PHPBB_ROOT_PATH') ? PHPBB_ROOT_PATH : './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include $phpbb_root_path . 'common.' . $phpEx;
$user->session_begin();
?>
C'est plutôt "sale", mais c'est à toi de voir.

Re: [phpBB] - Headers PHP capricieux...

Posté : 18 déc. 2013, 16:53
par casio
(...)
Il y a de forte chance qu'un autre mod existe avec la même fonctionnalité. (...)
Ha ? Je serais preneur sans pb.

Re: [phpBB] - Headers PHP capricieux...

Posté : 02 janv. 2014, 03:21
par casio
(...)
Voilà comment tu peux modifier ta page d'accueil :
(...)
ob_start(); // ligne à ajouter
(...)
C'est plutôt "sale", mais c'est à toi de voir.
En effet, le problème n'apparait plus, mais en quoi est-ce "sale" ?

N'existe t'il sinon pas un moyen de demander au script de vérifier que le header ne soit pas vide ?

Merci de votre aide...
Et bonne année 2014 :)