2

I have to make some changes on my old website where I'm not using any templating system. I'm loading the content for some pages from a database based on ?page parameter. So I have something like this:

<title>Page title</title>
...
...
...
$page_id = $_GET['page'];
include 'page.php'; //escaping is done in this file

Inside the page.php file I'm actually loading the information about the page. Based on this information I have to change the title of the main page.

I know that this design is not good at all and I wouldn't do this way these days, but to change everything on this website would be too complicated.

Thank you for your ideas.

Stephan Weinhold
  • 1,493
  • 1
  • 23
  • 34
Tony Vlcek
  • 338
  • 3
  • 17

3 Answers3

2

Try to add php code before title

<html>
<?php
$page_id=$_GET["page"];
include('page.php');
echo "<title>".$page_title."</title>";
?>
<body></body></html>
Craziest Hacker
  • 99
  • 3
  • 11
1

Inside page.php:

echo '<script>
document.title = "This is the new page title.";
</script>';

How to dynamically change a web page's title?

Enjoy !

Community
  • 1
  • 1
zeflex
  • 1,436
  • 1
  • 13
  • 27
0
<?php
$page_id = $_GET['page'];
if ($page_id == 'first value') {
 $title = 'first title';
} else {
 $title = 'second title';
}
?>
<title><?php echo $title?></title>
...<?php
include 'page.php'; //escaping is done in this file
Sanjay Kumar N S
  • 4,165
  • 3
  • 18
  • 34