This extension executes the custom php code specified by the administrator, each time a page is loaded.
The custom code is written in a single file which can be added everywhere among the website files. Then the path to that file is filled in the plugin parameters.
The great benefit is that you can still use the variables and functions of the Joomla framework like the code is written inside the official Joomla files.
This extension is free for download.