PHP: "Footer function"?
I have a project. It has a good number of PHP files. Each of these files includes a standard header. They don't include a standard footer.
Now I want to do something just before the end of every page. I can go through each page and add the footer code, but I was wondering if there is an easier way (and I think I've seen som开发者_如何学运维ething like it before, though I might be mistaken).
Is there a way to set a "hook" or "trigger" function that will be executed at the end of a page, from the included header PHP script? I'm thinking of something like set_error_handler but to handle a page close event. Or like C's atexit function.
Ah, I found the function I was looking for, FINALLY. Believe me, I've been searching for this for a while, and just happened upon it!
register_shutdown_function— Register a function for execution on shutdown
The auto_append_file
setting in php.ini will require
a file at the end of every PHP page:
http://us3.php.net/manual/en/ini.core.php#ini.auto-append-file
Note this applies site-wide to EVERY PHP file.
I think you're thinking of auto_prepend_file and auto_append_file:
http://www.aarongloege.com/blog/web-development/php/automatically-include-files/
精彩评论