基于PHP中包含的文件更改标题
我必须在我的旧网站上做一些改变,我没有使用任何模板系统。我正在根据基于PHP中包含的文件更改标题,php,include,title,Php,Include,Title,我必须在我的旧网站上做一些改变,我没有使用任何模板系统。我正在根据?page参数从数据库加载某些页面的内容。所以我有这样的想法: <title>Page title</title> ... ... ... $page_id = $_GET['page']; include 'page.php'; //escaping is done in this file 页面标题 ... ... ... $page\u id=$\u GET['page']; 包括“page.php
?page
参数从数据库加载某些页面的内容。所以我有这样的想法:
<title>Page title</title>
...
...
...
$page_id = $_GET['page'];
include 'page.php'; //escaping is done in this file
页面标题
...
...
...
$page\u id=$\u GET['page'];
包括“page.php”//转义在此文件中完成
在page.php
文件中,我实际上正在加载关于页面的信息。根据这些信息,我必须更改主页的标题
我知道这个设计一点也不好,我现在也不会这样做,但是改变这个网站上的一切太复杂了
谢谢你的想法。
<?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
…Inside page.php:
echo '<script>
document.title = "This is the new page title.";
</script>';
echo'
document.title=“这是新的页面标题。”;
';
享受吧 尝试在标题之前添加php代码
<html>
<?php
$page_id=$_GET["page"];
include('page.php');
echo "<title>".$page_title."</title>";
?>
<body></body></html>
添加要设置标题的代码。