I came across this nifty feature in PHP the other day, and thought I would share. It is particularly helpful for PHP web games, which often have to break out of a page with exit(), therefore breaking the rest of the page from being displayed unless you make complicated use of include files or make template functions. The actual feature lives in the
php.ini file. The actual values are:
...and...
What these do is they let you specific the path of a file that will
automatically be included before your code (prepend) and/or after your code (append). The most common use of this feature is to add your website header and footer into the respective file paths so that your static page header is added to the prepend path and your footer is added to the append path. That way, you can exit() from scripts or do any kind of logic you need to without worrying about whether or not the rest of your page is going to be displayed.
Typical usage on Windows would look something like this:
Code: Select all
auto_prepend_file = "c:/wamp/www/test/headertemplate.php"
(Use the auto_append_file path in the same way to have the contents of the file added to the end of all your pages)
Typical usage on Linux would look like this:
Code: Select all
auto_prepend_file = “/home/username/headertemplate.php”
The major downside to this is that I don't believe there is a way to set it on a page-by-page basis. However, that is also one of the positives about it. You give up some flexibility for complete convenience for the display of your website template, and it almost functions in the same way as ASP.NET's "Master Pages" feature where you only have to write and deal with "content areas" and not with the base template. The template itself is handled for you.
I hope some people find this as helpful as I believe it will be for me
