简体   繁体   中英

I need to add content at the end of each page

I have a client, whose website has 108 different php static pages, and we need to add some content at the end of each page. I want to avoid doing this manually. Is there any way I can add a link at the end of each page programmatically by using .htaccess or php?

Its a limited hosting account, no ssl

您可以使用auto_append_file

webbiedave's answer looks simple - but what happens when you append the content to...

<html>
...
</html>

Whether the text is rendered, and how it is rendered will depend very much on the browser. Also, as per the link provided "If the script is terminated with exit(), auto-append will not occur" - while PHP does a good job of cleaning up the resources at exit, it is still good practice to explicitly call exit when the code should terminate.

Although it's still not a generic solution, I'd go with auto prepend script containing something like:

<?php 
register_shutdown_function('add_footer');

function add_footer()
{
  // try loading a javascript to render the required text
  print '<script type="text/javascript" src="/somepath/addfooter.js"></script>' . "\n";
  // and for browsers with js disabled but which will render the text include it inline
  print '<noscript>' . $include_as_static_text_here . '</noscript>';
}

(IME a script tag appended after the closing html tag is generally acceptable to most browsers even though the resulting html is not well formed - and in the few cases where it is not, the worst that happens is that the script is ignored).

Then in addfooter.js, add the content to the end of the body of the document.

Obviously this will result in the content being sent twice in some cases - solutions to this should be obvious - but I've omitted them for reasons of time and clarity.

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