Il sito funziona alla perfezione; eccezion fatta per il tag TITLE che non si aggiorna al cambiar del contenuto delle pagine. Il problema è che l'header viene letto prima del body, quindi una eventuale variabile $title nell'header rimarrebbe senza valore, ma i tag <title></title> sono proprio nell'header.
La struttura dello script è semplice:
index.php richiama sempre menu.inc + header.inc + footer.inc + di volta in volta la pagina dei contenuti richiesta (esempio contenuto.inc).
L'ultimo tentativo che ho fatto è stato quello di associare ad ogni costante corrispondente ai contenuti, una variabile $title; però non riesco a richiamarla con echo $title; nel tag TITLE... ed anzi, ho forti dubbi che tale procedura sia ortodossa. Se qualcuno potesse aiutarmi a risolvere il problema gliene sarei molto grato. Ecco il codice:
index.php
Codice PHP:
<?php
// Includes definitions of menus
include_once("menu.inc");
/*
Check if a request arrives from a particular section.
If you did not request any particular section, set section current equal to SECTION_HOME
*/
if (!isset($_REQUEST['section'])) $section = SECTION_HOME;
else $section = $_REQUEST['section'];
// Includes header
include("header.inc");
// Print the menu
echo "<table>\n";
echo "<tr>";
reset($site_menu); $cspan=1;
foreach($site_menu as $menu) {
if ($section == $menu['code']) {
echo "<td class=\"sel-tab\">{$menu['name']}</td>\n";
if (is_array($menu['submenu'])) { // Generates the string of submenu
reset($menu['submenu']);
$submenu = array();
foreach($menu['submenu'] as $sm) $submenu[] = "<a href=\"index.php?section={$menu['code']}&option={$sm['code']}\" class=\"submenu\">{$sm['name']}</a>";
}
}
else echo "<td class=\"tab\"><a class=\"menu\" href=\"index.php?section={$menu['code']}\">{$menu['name']}</a></td>\n";
$cspan++;
}
echo "<td class=\"empty-tab\"></td>\n</tr>\n";
echo "<tr><td colspan=\"$cspan\" class=\"menubar\">";
if (isset($submenu)) echo implode(" ", $submenu);
echo "</td></tr>\n";
echo "</table>\n";
// Terminate a line of the body of the document
echo "\t</td>\n";
echo "</tr>";
// Prints specific messages to section
echo "<tr>\n\t<td class=\"corpo\">\n";
// Acts depending on the chosen section
$option = isset($_REQUEST['option']) ? $_REQUEST['option'] : false;
if($option === false)
{
switch($section) {
case SECTION_HOME: include("home.inc"); break;
case SECTION1: include("section1/section1.inc"); $title = 'Titolo pagina 1'; break;
case SECTION2: include("section2/section2.inc"); $title = 'Titolo pagina 2'; break;
case SECTION3: include("section3/section3.inc"); $title = 'Titolo pagina 3'; break;
case SECTION4: include("section4/section4.inc"); $title = 'Titolo pagina 4'; break;
case SECTION5: include("section5/section5.inc"); $title = 'Titolo pagina 5'; break;
default: continue;
}
}
else
{
switch($option) {
case SECTION1_SUBSECTION1: include("section1/subsection1.1.inc"); $title = 'Titolo pagina 1.1'; break;
case SECTION1_SUBSECTION2: include("section1/subsection1.2.inc"); $title = 'Titolo pagina 1.2'; break;
case SECTION1_SUBSECTION3: include("section1/subsection1.3.inc"); $title = 'Titolo pagina 1.3'; break;
case SECTION1_SUBSECTION4: include("section1/subsection1.4.inc"); $title = 'Titolo pagina 1.4'; break;
case SECTION1_SUBSECTION5: include("section1/subsection1.5.inc"); $title = 'Titolo pagina 1.5'; break;
case SECTION2_SUBSECTION1: include("section2/subsection2.1.inc"); $title = 'Titolo pagina 2.1'; break;
case SECTION2_SUBSECTION2: include("section2/subsection2.2.inc"); $title = 'Titolo pagina 2.2'; break;
case SECTION2_SUBSECTION3: include("section2/subsection2.3.inc"); $title = 'Titolo pagina 2.3'; break;
case SECTION2_SUBSECTION4: include("section2/subsection2.4.inc"); $title = 'Titolo pagina 2.4'; break;
case SECTION2_SUBSECTION5: include("section2/subsection2.5.inc"); $title = 'Titolo pagina 2.5'; break;
case SECTION3_SUBSECTION1: include("section3/subsection3.1.inc"); $title = 'Titolo pagina 3.1'; break;
case SECTION3_SUBSECTION2: include("section3/subsection3.2.inc"); $title = 'Titolo pagina 3.2'; break;
case SECTION3_SUBSECTION3: include("section3/subsection3.3.inc"); $title = 'Titolo pagina 3.3'; break;
case SECTION3_SUBSECTION4: include("section3/subsection3.4.inc"); $title = 'Titolo pagina 3.4'; break;
case SECTION3_SUBSECTION5: include("section3/subsection3.5.inc"); $title = 'Titolo pagina 3.5'; break;
case SECTION4_SUBSECTION1: include("section4/subsection4.1.inc"); $title = 'Titolo pagina 4.1'; break;
case SECTION4_SUBSECTION2: include("section4/subsection4.2.inc"); $title = 'Titolo pagina 4.2'; break;
case SECTION4_SUBSECTION3: include("section4/subsection4.3.inc"); $title = 'Titolo pagina 4.3'; break;
case SECTION4_SUBSECTION4: include("section4/subsection4.4.inc"); $title = 'Titolo pagina 4.4'; break;
case SECTION4_SUBSECTION5: include("section4/subsection4.5.inc"); $title = 'Titolo pagina 4.5'; break;
case SECTION5_SUBSECTION1: include("section5/subsection5.1.inc"); $title = 'Titolo pagina 5.1'; break;
case SECTION5_SUBSECTION2: include("section5/subsection5.2.inc"); $title = 'Titolo pagina 5.2'; break;
case SECTION5_SUBSECTION3: include("section5/subsection5.3.inc"); $title = 'Titolo pagina 5.3'; break;
case SECTION5_SUBSECTION4: include("section5/subsection5.4.inc"); $title = 'Titolo pagina 5.4'; break;
case SECTION5_SUBSECTION5: include("section5/subsection5.5.inc"); $title = 'Titolo pagina 5.5'; break;
default: continue;
}
}
echo "\t</td>\n</tr>\n";
// Include the footer
include("footer.inc");
?>
menu.inc
Codice PHP:
<?php
// Constant for the main sections
define("SECTION_HOME", 0);
define("SECTION1", 10);
define("SECTION2", 20);
define("SECTION3", 30);
define("SECTION4", 40);
define("SECTION5", 50);
// Constant for the subsections
define("SECTION1_SUBSECTION1", 101);
define("SECTION1_SUBSECTION2", 102);
define("SECTION1_SUBSECTION3", 103);
define("SECTION1_SUBSECTION4", 104);
define("SECTION1_SUBSECTION5", 105);
define("SECTION2_SUBSECTION1", 201);
define("SECTION2_SUBSECTION2", 202);
define("SECTION2_SUBSECTION3", 203);
define("SECTION2_SUBSECTION4", 204);
define("SECTION2_SUBSECTION5", 205);
define("SECTION3_SUBSECTION1", 301);
define("SECTION3_SUBSECTION2", 302);
define("SECTION3_SUBSECTION3", 303);
define("SECTION3_SUBSECTION4", 304);
define("SECTION3_SUBSECTION5", 305);
define("SECTION4_SUBSECTION1", 401);
define("SECTION4_SUBSECTION2", 402);
define("SECTION4_SUBSECTION3", 403);
define("SECTION4_SUBSECTION4", 404);
define("SECTION4_SUBSECTION5", 405);
define("SECTION5_SUBSECTION1", 501);
define("SECTION5_SUBSECTION2", 502);
define("SECTION5_SUBSECTION3", 503);
define("SECTION5_SUBSECTION4", 504);
define("SECTION5_SUBSECTION5", 505);
// Array that contains the menu
$site_menu = array(
0 => array(
"name" => "Home", // Name of Section
"code" => SECTION_HOME, // Code of the section, using a constant pre-defined
"submenu" => NULL // Array with subsections of the main section
),
1 => array(
"name" => "Section 1", // Name of Section
"code" => SECTION1, // Code of the section, using a constant pre-defined
"submenu" => array( // Start the section 1 submenu
0 => array (
"name" => "Section 1.1",
"code" => SECTION1_SUBSECTION1,
),
1 => array (
"name" => "Section 1.2",
"code" => SECTION1_SUBSECTION2,
),
2 => array (
"name" => "Section 1.3",
"code" => SECTION1_SUBSECTION3,
),
3 => array (
"name" => "Section 1.4",
"code" => SECTION1_SUBSECTION4,
),
4 => array (
"name" => "Section 1.5",
"code" => SECTION1_SUBSECTION5,
),
)
), // Close the section 1 submenu
2 => array(
"name" => "Section 2", // Name of Section
"code" => SECTION2, // Code of the section, using a constant pre-defined
"submenu" => array( // Start the section 2 submenu
0 => array (
"name" => "Section 2.1",
"code" => SECTION2_SUBSECTION1,
),
1 => array (
"name" => "Section 2.2",
"code" => SECTION2_SUBSECTION2,
),
2 => array (
"name" => "Section 2.3",
"code" => SECTION2_SUBSECTION3,
),
3 => array (
"name" => "Section 2.4",
"code" => SECTION2_SUBSECTION4,
),
4 => array (
"name" => "Section 2.5",
"code" => SECTION2_SUBSECTION5,
),
)
), // Close the section 2 submenu
3 => array(
"name" => "Section 3", // Name of Section
"code" => SECTION3, // Code of the section, using a constant pre-defined
"submenu" => array( // Start the section 3 submenu
0 => array (
"name" => "Section 3.1",
"code" => SECTION3_SUBSECTION1,
),
1 => array (
"name" => "Section 3.2",
"code" => SECTION3_SUBSECTION2,
),
2 => array (
"name" => "Section 3.3",
"code" => SECTION3_SUBSECTION3,
),
3 => array (
"name" => "Section 3.4",
"code" => SECTION3_SUBSECTION4,
),
4 => array (
"name" => "Section 3.5",
"code" => SECTION3_SUBSECTION5,
),
)
), // Close the section 3 submenu
4 => array(
"name" => "Section 4", // Name of Section
"code" => SECTION4, // Code of the section, using a constant pre-defined
"submenu" => array( // Start the section 4 submenu
0 => array (
"name" => "Section 4.1",
"code" => SECTION4_SUBSECTION1,
),
1 => array (
"name" => "Section 4.2",
"code" => SECTION4_SUBSECTION2,
),
2 => array (
"name" => "Section 4.3",
"code" => SECTION4_SUBSECTION3,
),
3 => array (
"name" => "Section 4.4",
"code" => SECTION4_SUBSECTION4,
),
4 => array (
"name" => "Section 4.5",
"code" => SECTION4_SUBSECTION5,
),
)
), // Close the section 4 submenu
5 => array(
"name" => "Section 5", // Name of Section
"code" => SECTION5, // Code of the section, using a constant pre-defined
"submenu" => array( // Start the section 5 submenu
0 => array (
"name" => "Section 5.1",
"code" => SECTION5_SUBSECTION1,
),
1 => array (
"name" => "Section 5.2",
"code" => SECTION5_SUBSECTION2,
),
2 => array (
"name" => "Section 5.3",
"code" => SECTION5_SUBSECTION3,
),
3 => array (
"name" => "Section 5.4",
"code" => SECTION5_SUBSECTION4,
),
4 => array (
"name" => "Section 5.5",
"code" => SECTION5_SUBSECTION5,
),
)
), // Close the section 5 submenu
); // Close the menu
?>
header.inc
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" charset="utf-8" />
<title><?php echo $title; ?></title>
</head>
<body>
<table>
<tr>
<td>
contenuto.inc
Codice PHP:
<h1>Toonik</h1>
<div class="home">
Ciao <?php echo $ip = getenv("REMOTE_ADDR"); ?>
Perfect it work... Installation successful!
You can freely use this framework to develop your Personal Home Page.
First of all you have to read the [url="README.txt"]README[/url] file.
Have a lot of fun !
- - - - - - - - - - -
</p>
</div>
footer.inc
Codice PHP:
<tr>
<td id="footer">
[url="http://validator.w3.org/check?uri=referer"]xhtml validator[/url]
[url="http://jigsaw.w3.org/css-validator/check?uri=referer"]css validator[/url]
</td>
</tr>
</table>
</body>
</html>
Grazie