This article illustrates the usage of auto_prepend_file and auto_append_file in PHP, which is a practical technique in PHP programming. Share to everyone for your reference. The specific methods are as follows:
If you need to require the file to the top and bottom of all pages.
The first method: Add the Require statement at the top and bottom of all pages.
For example:
Require (' header.php ');
Page body Content part
require (' footer.php ');
However, if you need to modify the file path at the top or bottom require, you will need to modify all the paging files. and need each page to add require statement, more trouble.
The second method: use Auto_prepend_file and auto_append_file to require files at the top and bottom of all pages.
There are two items in the php.ini:
Auto_prepend_file load files at the top of the page
auto_append_file load files at the bottom of the page
You can use this method without any changes to the page, when you need to modify the top or bottom require file, only need to modify the value of Auto_prepend_file and Auto_append_file.
For example: Modify PHP.ini, modify auto_prepend_file and Auto_append_file values.
Auto_prepend_file = "/home/fdipzone/header.php"
auto_append_file = "/home/fdipzone/footer.php"
Reboot the server after modification so that all the top and bottom of the page will be require/home/fdipzone/header.php and/home/fdipzone/footer.php
Note:auto_prepend_file and Auto_append_file can only require a PHP file, but this PHP file can require several other PHP files.
If you don't need all the pages to require files at the top or bottom, you can specify a paging file within a folder to call Auto_prepend_file and Auto_append_file
Add the. htaccess file in the folder where you want to load the top or bottom files as follows:
Php_value auto_prepend_file "/home/fdipzone/header.php"
php_value auto_append_file "/home/fdipzone/footer.php"
This allows the paging file in the specified. htaccess folder to load/home/fdipzone/header.php and/home/fdipzone/footer.php, and other paging files will not be affected.
Use the. htaccess settings, more flexible, no need to restart the server, and do not require administrator rights, the only disadvantage is that each read and interpreted files in the directory to be processed each time, rather than at the start of processing once, so performance will be reduced.
I hope this article will help you with the learning of PHP programming.