Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I prepend a PHP file using .htaccess?

Tags:

php

.htaccess

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

Img

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?

like image 872
Sainan Avatar asked Feb 09 '16 17:02

Sainan


1 Answers

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) {
  ...
}
like image 145
maxhb Avatar answered Sep 27 '22 22:09

maxhb