Variable auto_prepend_file?


Variable auto_prepend_file?

好吧,我的问题标题很烂XD如果有人有更好的标题,请编辑!

不管怎样,我的php.ini文件中有这个:

auto_prepend_file = ./include/startup.php
auto_append_file = ./include/shutdown.php

startup.php看起来像这样:

<?php
chdir(__DIR__."/..");
require("include/db.php");
// more setup stuff here
if( $_SERVER['REQUEST_METHOD'] == "AJAX") { // yup, custom HTTP method :p
    // parse file_get_contents("php://input")
}
else {
    $output_footer = true;
    require("include/header.php");
}

shutdown.php是这样的:

<?php
if( isset($output_footer)) require("include/footer.php");

现在,谈谈主要问题。


header.php包括行CCD_ 1。我希望该标题取决于当前正在查看的页面。目前,我有一些丑陋的黑客攻击,涉及JavaScript:

document.title = document.getElementsByTagName('h1')[0].textContent;

显然,这并不理想!当所述标题作为auto_prepend_file的结果输出时,有关于如何调整标题的建议吗?

我认为您不应该使用这样的附加和前置功能,但这只是我的意见。

为什么不创建header.php以允许使用可变标题文本呢。并完全删除预端和附加脚本

<title><?php echo (isset($title)) ? $title : 'default title'; ?></title>

只要你需要一个标题标签。

$title = "some title";
require("include/header.php");