简体   繁体   中英

Variable auto_prepend_file?

Okay, I suck at titling my questions XD If anyone has a better title, please edit!

Anyway, I have this in my php.ini file:

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

startup.php looks something like this:

<?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 goes something like this:

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

Now, on to the main problem.


header.php includes the line <title>My shiny new site</title> . I want that title to depend on the page that is currently being viewed. At the moment, I have some ugly hack that involves JavaScript:

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

Obviously, this is not ideal! Any suggestions on how to adjust the title when said title is being output as a result of an auto_prepend_file?

I don't think you should use the append and prepend functionality like that But that's just my opinion.

Why not create header.php to allow for a variable title text. And drop the prepend and append scripts completely

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

And whenever you need a title tag.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM