Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 22
  1. #1

    Cambiare il valore del tag TITLE in base alla pagina caricata

    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']}&amp;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(
      
    => 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
      
    ),

    => 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
                    
    => array (
                  
    "name" => "Section 1.1",
                  
    "code" => SECTION1_SUBSECTION1,
            ),
                
    => array (
                  
    "name" => "Section 1.2",
                  
    "code" => SECTION1_SUBSECTION2,
            ),
                
    => array (
                  
    "name" => "Section 1.3",
                  
    "code" => SECTION1_SUBSECTION3,
            ),
                
    => array (
                  
    "name" => "Section 1.4",
                  
    "code" => SECTION1_SUBSECTION4,
            ),
                
    => array (
                  
    "name" => "Section 1.5",
                  
    "code" => SECTION1_SUBSECTION5,
            ),
        ) 
      ),  
    // Close the section 1 submenu

    => 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
                    
    => array (
                  
    "name" => "Section 2.1",
                  
    "code" => SECTION2_SUBSECTION1,
            ),
                
    => array (
                  
    "name" => "Section 2.2",
                  
    "code" => SECTION2_SUBSECTION2,
            ),
                
    => array (
                  
    "name" => "Section 2.3",
                  
    "code" => SECTION2_SUBSECTION3,
            ),
                
    => array (
                  
    "name" => "Section 2.4",
                  
    "code" => SECTION2_SUBSECTION4,
            ),
                
    => array (
                  
    "name" => "Section 2.5",
                  
    "code" => SECTION2_SUBSECTION5,
            ),
        ) 
      ),  
    // Close the section 2 submenu

    => 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
                    
    => array (
                  
    "name" => "Section 3.1",
                  
    "code" => SECTION3_SUBSECTION1,
            ),
                
    => array (
                  
    "name" => "Section 3.2",
                  
    "code" => SECTION3_SUBSECTION2,
            ),
                
    => array (
                  
    "name" => "Section 3.3",
                  
    "code" => SECTION3_SUBSECTION3,
            ),
                
    => array (
                  
    "name" => "Section 3.4",
                  
    "code" => SECTION3_SUBSECTION4,
            ),
                
    => array (
                  
    "name" => "Section 3.5",
                  
    "code" => SECTION3_SUBSECTION5,
            ),
        ) 
      ),  
    // Close the section 3 submenu

    => 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
                    
    => array (
                  
    "name" => "Section 4.1",
                  
    "code" => SECTION4_SUBSECTION1,
            ),
                
    => array (
                  
    "name" => "Section 4.2",
                  
    "code" => SECTION4_SUBSECTION2,
            ),
                
    => array (
                  
    "name" => "Section 4.3",
                  
    "code" => SECTION4_SUBSECTION3,
            ),
                
    => array (
                  
    "name" => "Section 4.4",
                  
    "code" => SECTION4_SUBSECTION4,
            ),
                
    => array (
                  
    "name" => "Section 4.5",
                  
    "code" => SECTION4_SUBSECTION5,
            ),
        ) 
      ),  
    // Close the section 4 submenu

    => 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
                    
    => array (
                  
    "name" => "Section 5.1",
                  
    "code" => SECTION5_SUBSECTION1,
            ),
                
    => array (
                  
    "name" => "Section 5.2",
                  
    "code" => SECTION5_SUBSECTION2,
            ),
                
    => array (
                  
    "name" => "Section 5.3",
                  
    "code" => SECTION5_SUBSECTION3,
            ),
                
    => array (
                  
    "name" => "Section 5.4",
                  
    "code" => SECTION5_SUBSECTION4,
            ),
                
    => 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
    - - - -Toonik- - - -
    Debian GNU/Linux

  2. #2
    Utente di HTML.it L'avatar di oronze
    Registrato dal
    Jun 2001
    Messaggi
    3,543
    io ho sempre fatto così....la struttura della pagina è
    <?php
    $tit = "titolo pagina";
    include("head.php");
    contenuto pagina
    include("foot.php);
    ?>
    in questo modo, le varie pagine, oltre a cambiare il contenuto cambiano il valore della variabile $tit

    No ai layout tabellari!

    Insulto libero: http://forum.html.it/forum/showthread.php?s=&postid=12524872#post12524872

  3. #3
    Ciao Oronze,

    ma: $tit = "titolo pagina"; lo inserisci nell'index o nella pagina del contenuto?
    - - - -Toonik- - - -
    Debian GNU/Linux

  4. #4
    Utente di HTML.it L'avatar di oronze
    Registrato dal
    Jun 2001
    Messaggi
    3,543
    lo inserisco in tutte le pagine, per esempio, index.php, contatti.php, azienda.php, iscriviti.php, etc...

    No ai layout tabellari!

    Insulto libero: http://forum.html.it/forum/showthread.php?s=&postid=12524872#post12524872

  5. #5
    @Oronze,

    ho capito il tuo metodo, ma non lo posso applicare al codice in oggetto; comporterebbe una riscrittura totale, che invece devo evitare.

    Comunque grazie delle dritte
    - - - -Toonik- - - -
    Debian GNU/Linux

  6. #6
    Utente di HTML.it L'avatar di oronze
    Registrato dal
    Jun 2001
    Messaggi
    3,543
    se usi una sola pagina non puoi fare una cosa del tipo
    Codice PHP:
    <?php
    if($option === false)
    {
        switch(
    $section) {
          case 
    SECTION_HOME$pagina="home.inc"$title 'Home page'; break;
          case 
    SECTION1$pagina="section1/section1.inc"$title 'Titolo pagina 1'; break;
          default: continue;
        }
    }
    else
    {
        switch(
    $option) {
          case 
    SECTION1_SUBSECTION1:$pagina="section1/subsection1.1.inc"$title 'Titolo pagina 1.1'; break;
    case 
    SECTION1_SUBSECTION2$pagina="section1/subsection1.2.inc"$title 'Titolo pagina 1.2'; break;
    default: continue;
        }

    ?>
    <html>
    <head>
    <title><?php echo ($title); ?></title>
    </head>
    <body>
    [tutto il codice]
    dove devi includere la pagina fai

    <?php
    include($pagina);
    ?>
    </body>
    </html>
    o non ho capito io la struttura? purtroppo sono troppe righe di codice da leggere in poco tempo che ho

    No ai layout tabellari!

    Insulto libero: http://forum.html.it/forum/showthread.php?s=&postid=12524872#post12524872

  7. #7
    Ciao Oronze,
    scusa per il ritardo, ma sono in clamoroso ritardo con dei lavori e non riesco ad aver tempo per le mie cose... un po' come il calzolaio con le scarpe rotte ;-)
    Comunque appena posso, provo a riscrivere parte del codice seguendo le tue indicazioni... magari riesco a trovare il giusto compromesso per ottenere un title dinamico senza snaturare la struttura esistente... ti farò sapere. Se nel frattempo volessi vedere la mia struttura all'opera ecco il link: http://toonik.altervista.org/
    - - - -Toonik- - - -
    Debian GNU/Linux

  8. #8
    Non mi sono messo a guardare tutto di quello che avete scritto... ma io ho un sito in pratica con una sola pagina, le sezioni sono delle variabili , come anche il titolo della sezione.

    Codice PHP:
    $titolo_pagina $_GET['sez'];
    include 
    'header.php';
    header_pagina($titolo); 
    ovviamente il titolo della pagina posso anche prenderlo da database, passo il parametro ad una mia funzione in php, che mette dentro al title quello che gli passo

  9. #9
    @goikiu
    grazie anche a te per il contributo, ma purtroppo temo di non essere in grado di applicare quanto da te consigliato. Premetto che sto iniziando ad usare php e quindi non sono ancora in grado di capire al volo dei concetti che per degli esperti potrebbero essere ovvi. Mi dispiace di non riuscire a risolvere questo (apparentemente banale) problema, perché sto realizzato una struttura di base (pubblicata su SourceForge), utile a creare in pochi minuti un sito web valido w3c. Sino a questo scoglio, sembrava andare tuto bene... poi alcuni utenti mi hanno fatto presente che avrebbero gradito in Myphage (questo è il nome del progetto) il title dinamico ed io dopo vari tentativi (senza successo) ho deciso di chiedere aiuto nel forum. Ora, pur avendo tentato di mettere in pratica i vari consigli, non sono riuscito a risolvere nulla, quindi lancio un appello, per chiedere a qualche volenteroso di dare un'occhiata al codice originale (che è ben commentato e di facile comprensione). Ovviamente l'eventuale funzione di title dinamico verrà distribuita come patch di Myphage(per questo non posso stravolgere la struttura di base), quindi sarà dato il giusto merito a chi vorrà aiutarmi. Come detto il progetto è pubblicato su SourceForge ed è disponibile per il download gratuito a questo indirizzo: http://sourceforge.net/projects/myphage/

    Grazie in anticipo a quanti vorranno contribuire
    - - - -Toonik- - - -
    Debian GNU/Linux

  10. #10
    UP
    - - - -Toonik- - - -
    Debian GNU/Linux

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.