《PHP學(xué)習(xí):PHP中auto_prepend_file與auto_append_file用法實(shí)例分析》要點(diǎn):
本文介紹了PHP學(xué)習(xí):PHP中auto_prepend_file與auto_append_file用法實(shí)例分析,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
PHP實(shí)例本文實(shí)例講述了PHP中auto_prepend_file與auto_append_file的用法,是PHP程序設(shè)計(jì)中比較實(shí)用的技巧.分享給大家供大家參考.具體辦法如下:
PHP實(shí)例如果需要將文件require到所有頁(yè)面的頂部與底部.
PHP實(shí)例第一種辦法:在所有頁(yè)面的頂部與底部都加入require語(yǔ)句.
例如:
PHP實(shí)例
require('header.php');
//頁(yè)面正文內(nèi)容部分
require('footer.php');
PHP實(shí)例但這種辦法如果需要修改頂部或底部require的文件路徑,則需要修改所有頁(yè)面文件.而且需要每個(gè)頁(yè)面都加入require語(yǔ)句,比較麻煩.
PHP實(shí)例第二種辦法:使用auto_prepend_file與auto_append_file在所有頁(yè)面的頂部與底部require文件.
PHP實(shí)例php.ini中有兩項(xiàng):
auto_prepend_file 在頁(yè)面頂部加載文件
auto_append_file? 在頁(yè)面底部加載文件
PHP實(shí)例使用這種辦法可以不需要改動(dòng)任何頁(yè)面,當(dāng)需要修改頂部或底部require文件時(shí),只需要修改auto_prepend_file與auto_append_file的值即可.
PHP實(shí)例例如:修改php.ini,修改auto_prepend_file與auto_append_file的值.
PHP實(shí)例
auto_prepend_file = "/home/fdipzone/header.php"
auto_append_file = "/home/fdipzone/footer.php"
PHP實(shí)例修改后重啟服務(wù)器,這樣所有頁(yè)面的頂部與底部都會(huì)require /home/fdipzone/header.php 與 /home/fdipzone/footer.php
PHP實(shí)例注意:auto_prepend_file 與 auto_append_file 只能require一個(gè)php文件,但這個(gè)php文件內(nèi)可以require多個(gè)其他的php文件.
PHP實(shí)例如果不需要所有頁(yè)面都在頂部或底部require文件,可以指定某一個(gè)文件夾內(nèi)的頁(yè)面文件才調(diào)用auto_prepend_file與auto_append_file
在需要頂部或底部加載文件的文件夾中加入.htaccess文件,內(nèi)容如下:
PHP實(shí)例
php_value auto_prepend_file "/home/fdipzone/header.php"
php_value auto_append_file "/home/fdipzone/footer.php"
PHP實(shí)例這樣在指定.htaccess的文件夾內(nèi)的頁(yè)面文件才會(huì)加載 /home/fdipzone/header.php 與 /home/fdipzone/footer.php,其他頁(yè)面文件不受影響.
PHP實(shí)例使用.htaccess設(shè)置,比較靈活,不需要重啟服務(wù)器,也不需要管理員權(quán)限,唯一缺點(diǎn)是目錄中每個(gè)被讀取和被解釋的文件每次都要進(jìn)行處理,而不是在啟動(dòng)時(shí)處理一次,所以性能會(huì)有所降低.
PHP實(shí)例希望本文所述對(duì)大家PHP程序設(shè)計(jì)的學(xué)習(xí)有所贊助.
歡迎參與《PHP學(xué)習(xí):PHP中auto_prepend_file與auto_append_file用法實(shí)例分析》討論,分享您的想法,維易PHP學(xué)院為您提供專業(yè)教程。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/14695.html