<? function viewheader() { ?>
<?php
$start = microtime(true);
?>
<!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=iso-8859-1" />
<META Http-Equiv="Content-Language" Content="fr">
<title><?php echo $board_titre; ?></title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/bbcode.css" type="text/css" />
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript" src="js/popup_dl.js"></script>
<script type="text/javascript" src="js/bbcode.js"></script>
<script type="text/javascript" src="js/bbc_box.js"></script>
</head>
<a name="top" id="top"></a>
<table cellpadding="0" cellspacing="0" align="center" width="900" height="120">
<tr>
<td align="center"><img src="images/logo.png" /></td>
</tr>
</table>
<? } ?>
<? function viewfooter() { ?>
<table cellpadding="0" cellspacing="0" align="center" width="900" height="25">
<tr>
<td> </td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" align="center" width="900">
<tr>
<td class="bar_l"> </td>
<td class="bar" width="100%" align="center"><h1>Copyright © 2007 | <a href="stats.php" class="linkfooter">Voir les statistiques</a></h1></td>
<td class="bar_r"> </td>
</tr>
</table>
<?php
$end = microtime(true);
$delta = $end - $start;
echo '<br /><div align="center">Page générée en : '. round($delta,2) .' secondes.</div>';
?>
</body>
</html>
<? } ?>
<?
function redirection($url){
echo "<script type=\"text/javascript\">\n"
. "<!--\n"
. "\n"
. "function redirect() {\n"
. "window.location='" . html_entity_decode($url) . "'\n"
. "}\n"
. "setTimeout('redirect()','2000');\n"
. "\n"
. "// -->\n"
. "</script>\n";
}
?>
<?php
session_start();
include('config.inc.php');
require('function.php') ;
$c = @mysql_connect($host,$login_host,$pass_host) or die('connection impossible');
@mysql_select_db($hostname,$c) or die('selection impossible');
?>
<?php viewheader(); ?>
<table cellpadding="0" cellspacing="0" align="center" width="900">
<tr>
<td valign="top">
<table cellpadding="0" cellspacing="0" align="center" width="685">
<tr>
<td class="bar_l"> </td>
<td class="bar" width="100%"><h2>Acceuil</h2></td>
<td class="bar_r"> </td>
</tr>
</table>
<br />
<table cellpadding="0" cellspacing="0" class="tableBorder" align="center" width="685">
<tr>
<td class="titre" height="21"><b>Bienvenue</b></td>
</tr>
<tr>
<td>Bonjour et bienvenue.</td>
</tr>
</table>
<br />
</td>
<td width="15" valign="top"> </td>
<td valign="top"><? include('includes/menu.php'); ?></td>
</tr>
</table>
<? viewfooter(); ?>
Non, la variable dans ta fonction a une portée locale, et donc la variable $board_titre à l'intérieur de ta fonction n'est pas la même que la variable $board_titre dans le reste du script. Il donc faut indiquer dans ta fonction que la variable $board_titre est globale et non locale...Il dise que l'on doit récuperer la donnée avant de l'afficher mais c'est ce qui est fait dans l'ordre des fichiers
En français ?D'accord mais je fais comment car dans le lien que m'as donné il additionne les champs
global $variable;
Ensuite, je n'avais pas tilté avant, mais plutôt que de mettre ton header dans une fonction, pourquoi ne le mettrais-tu pas dans un fichier spécifique header.php que tu incluerais au bon endroit ?$c = mysql_connect($host,$login_host,$pass_host) or die('connection impossible');
mysql_select_db($hostname,$c) or die('selection impossible');
$requete = mysql_query("SELECT * FROM ".$prefixe."_config") or die("Erreur : " . mysql_error());
$var = mysql_fetch_array ($requete);
function board_config() {
global $board_titre, $board_flags;
}
?>
Et dans mon fichier function.php, je dois mettre cela<? function viewheader() { ?>
<?php
$start = microtime(true);
board_config();
?>
<!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=iso-8859-1" />
<META Http-Equiv="Content-Language" Content="fr">
<title><?php echo $board_titre; ?></title>
</head>
<? } ?>
Pour le header c'est parce que j'ai voulu essayer les fonction pour éviter d'avoir un fichier header.php, fonction.php, et footer.php
function machin()
{
global $truc;
$truc = 'Cette variable est globale';
$machin = 'Cette variable est locale';
}
$truc est globale dans la fonction machin parce que l'on a indiqué global $truc au début de la fonction, $machin est locale parce que l'on n'a rien indiqué. Il n'y a pas besoin de créer une nouvelle fonction. Il faut juste indiquer dans la fonction quelles variables doivent être cherchées dans le contexte global.function board_config()
{
global $board_titre, $board_flags;
$board_titre = ''.$var['nomsite'].'';
$board_flags = ''.$var['flag'].'';
}
et ceci aussi
$nomsite = $var['nomsite'];
$flag = $var['flag'];
function board_config()
{
global $board_titre, $board_flags;
$board_titre = '$nomsite';
$board_flags = '$flag';
}
Mais aucun des 2 ne fonctionnent.
<?
if( $board_flags = 1)
{
echo '
<tr>
<td width="150"><b>Votre pays:</b></td>
<td><select name="pays"onchange="javascript:document.getElementById(\'flags\').src=\'images/flags/\'+this.value+\'.png\'">
<option value="00" selected="selected">Choisissez</option>
<option value="01">Afghanistan</option>
<option value="02">Albanie</option>
etc .............................
</select> <img id="flags" src="transparent.png" /></td>
</tr>
<tr>
<td> </td>
</tr>
';
}
?>
Dans ma base la donnée board_flags est a 0 donc le champ ne devrait pas s'afficher