Analysis of Auto_prepend_file and auto_append_file usages in PHP _php techniques

Source: Internet
Author: User
Tags php programming

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.