Analysis of auto_prepend_file and auto_append_file usage examples in PHP

Source: Internet
Author: User
Tags learn php programming
This article mainly introduces the usage of auto_prepend_file and auto_append_file in PHP. it describes the rest of configuration information and the usage and precautions of functions in detail, for more information about how to use auto_prepend_file and auto_append_file in PHP, it is a practical technique in PHP programming. Share it with you for your reference. The specific method is as follows:

To send the file require to the top and bottom of all pages.

Method 1: Add The require statement to the top and bottom of all pages.
For example:

Require ('header. php'); // require ('footer. php') in the content of the page body ');

However, if you need to modify the require file path at the top or bottom of the page, you need to modify all the page files. In addition, it is troublesome to add the require statement to each page.

Method 2: use auto_prepend_file and auto_append_file to specify the require file at the top and bottom of all pages.

Php. ini contains two items:

Auto_prepend_file: load the file at the top of the page
Auto_append_file: load the file at the bottom of the page

To use this method, you do not need to change any pages. to modify the require file at the top or bottom, you only need to modify the values of auto_prepend_file and auto_append_file.

For example, modify php. ini and the values of auto_prepend_file and auto_append_file.

auto_prepend_file = "/home/fdipzone/header.php"auto_append_file = "/home/fdipzone/footer.php"

Restart the server after modification, so that the top and bottom of all pages will be require/home/fdipzone/header. php and/home/fdipzone/footer. php

Note: auto_prepend_file and auto_append_file can only require one php file, but this php file can require multiple other PHP files.

If you do not need all the pages to be on the top or bottom of the require file, you can specify a page file in a folder to call auto_prepend_file and auto_append_file
Add the. htaccess file to the folder that needs to load files at the top or bottom. the content is as follows:

php_value auto_prepend_file "/home/fdipzone/header.php"php_value auto_append_file "/home/fdipzone/footer.php"

In this way, the page files in the specified. htaccess folder will load/home/fdipzone/header. php and/home/fdipzone/footer. php. Other page files will not be affected.

Use. htaccess settings are flexible. you do not need to restart the server or administrator permissions. The only drawback is that each file read and interpreted in the directory must be processed each time, instead of processing it once at startup, the performance will be reduced.

I hope this article will help you learn 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.