auto_prepend_file ・ auto_append_file ディレクティブについて
auto_prepend_file という php.iniディレクティブがあります。
このディレクティブの値として指定されたファイルは、リクエストされたPHPスクリプト(メインスクリプト)の実行前に読み込まれます。
一方、auto_append_file で指定されたファイルは、スクリプトの実行後に読み込まれます。
つまり、自動でrequire関数が実行されるような感じになります。
設定の方法
すべてのスクリプトからインクルードされているファイルなどがあれば、この auto_prepend_file ディレクティブで自動的に読み込むようにしておくと便利です。
例えば、自動的に読み込みたいファイルが /home/user/public_html/config.php だとすると、下記のように php.ini を編集します。
# vi /etc/php.ini
Automatically add files before or after any PHP document.
auto_prepend_file = /home/user/public_html/config.php
auto_append_file = /home/user/public_html/append_file.php
.htaccess で設定する場合は下記のように記述します。
# vi .htaccess php_value auto_prepend_file "/home/user/public_html/config.php"
exit()でスクリプトを終了した場合は、auto_append_fileによる自動付加機能は利用できないようなので注意が必要です。
注意: スクリプトが exit() で終了する場合、 この自動付加機能は使用されません 。PHP: コア php.ini ディレクティブに関する説明 - Manual
最終更新 2010-03-30

この記事へのコメント
まだコメントは投稿されていません。