Can I add a PHP file using .htaccess?

So, I read Twitter a bit until I saw this tweet from @DivineOmega :

Img

The ideal PHP error handler (to a large extent), I encoded it and I wanted to use it on the server, but How can I apply this file to all my PHP scripts?

+4
source share
1 answer

You can use phps auto_prepend_fileand directives auto_append_file.

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

.htaccess:

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

php.ini ( cgi-, - wole):

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

before.php

try {

after.php

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

Source: https://habr.com/ru/post/1628003/


All Articles