简体   繁体   中英

Can I prepend a PHP file using .htaccess?

So I was reading Twitter a bit until I saw this tweet by @DivineOmega :

图

The perfect PHP error handler (pretty much), I coded it and I wanted to use it server-wide, but How can I apply this file to all my PHP scripts?

You can use phps auto_prepend_file and auto_append_file directives.

It works like loading every script on your server via require_once() right between the files specified by auto_prepend_file (Loaded before your script) and auto_append_file (Loaded right after your script).

To activate in .htaccess :

php_value auto_prepend_file "/path/to/file/before.php"
php_value auto_append_file "/path/to/file/after.php"

Or in php.ini (required when running in cgi-mode, affects wole webserver):

auto_prepend_file  = "/path/to/file/before.php"
auto_append_file   = "/path/to/file/after.php"

before.php

try {

after.php

} catch(Exception $e) {
  ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM