Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Tytuł strony inny na każdej stronie.
GoldeNx3
post
Post #1





Grupa: Zarejestrowani
Postów: 228
Pomógł: 1
Dołączył: 24.12.2010

Ostrzeżenie: (0%)
-----


Witam! Mam tak napisaną stronę:

  1. <html>
  2. <head>
  3. <title>Tytuł</title>
  4.  
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  6. <meta name="description" content="desc" />
  7. <meta name="keywords" content="key" />
  8.  
  9. <link rel="stylesheet" href="style.css" type="text/css" />
  10. </head>
  11.  
  12. <body>
  13.  
  14. <?php
  15. define('DIR', 'pages/');
  16.  
  17. switch($_GET['mdl'])
  18. {
  19. case $_GET['mdl']:
  20. if(file_exists(DIR . $_GET['mdl'] . '.php')){
  21. include(DIR . $_GET['mdl'] . '.php');
  22. }
  23. break;
  24. }
  25. ?>
  26.  
  27. </body>
  28. </html>


Oczywiście usunąłem co nie potrzebne.
Ale tutaj mam tytuł strony tylko jeden. ("Tytuł")
A co, jak w zależności od strony chciałbym dać inny tytuł strony? To jak?

Ten post edytował GoldeNx3 13.04.2012, 14:48:02
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
tolomei
post
Post #2





Grupa: Zarejestrowani
Postów: 450
Pomógł: 135
Dołączył: 18.11.2010
Skąd: Wschowa

Ostrzeżenie: (0%)
-----


Korzystając z ostatniego listingu:

  1. <?php
  2.  
  3.  
  4. define('DIR', 'pages/');
  5.  
  6. $plik = isset($_GET['mdl']) ? preg_replace('#\W#', '', $_GET['mdl']) : null;
  7.  
  8. if(!empty($plik) && $plikfile_exists(DIR . $plik . '.php')){
  9. include(DIR . $plik . '.php');
  10. } else {
  11. include(DIR . 'home.php');
  12. }
  13.  
  14. $buffer = ob_get_clean();
  15.  
  16. ?>
  17.  
  18. <html>
  19. <head>
  20. <title><?php echo isset($title) ? $title : 'Tytuł strony'; ?></title>
  21.  
  22. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  23. <meta name="description" content="desc" />
  24. <meta name="keywords" content="key" />
  25.  
  26. <link rel="stylesheet" href="style.css" type="text/css" />
  27. </head>
  28.  
  29. <body>
  30.  
  31. <?php
  32. echo $buffer;
  33. ?>
  34.  
  35. </body>
  36. </html>


Teraz w linii 7. masz włączone filtrowanie nazwy pliku. Dokładniej, wszystkie znaki, które nie są dużą/małą literą, cyfrą lub podkreśleniem zostaną usunięte z nazwy.
Dodatkowo w linii 12. masz włączone załączanie strony domyślnej w przypadku braku nazwy lub gdy plik nie istnieje.

Pozdrawiam.

Ten post edytował tolomei 14.04.2012, 00:40:52
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 08:31