I need to run a PHP script every time someone visits a URL on my web page. how can I do this with apache2.4 and PHP-FPM? I also needed to preserve all the data (like the headers) from Apache. I am trying to use PHP and on every url even the errors.
I need to run a PHP script every time someone visits a URL on my web page. how can I do this with apache2.4 and PHP-FPM? I also needed to preserve all the data (like the headers) from Apache. I am trying to use PHP and on every url even the errors.
2
Answers
You can just include the file containing the code (file.php) you want to execute in top of your php code like this and it will execute everytime someone visits your original php file:
If you want to preserve the header information too. Capture that in some variable and array and pass that to your file.php.
For passing the header information, you might need a function for that in your file.php file.
You can send those information as parameters via calling your function. Better to use classes.
What you can do is to have php.ini autoprepend a script to each of your pages.
This should be a starting point for you:
Note that php.ini is server related so this will affect all sites you host unless you do something like what is described here to have a php.ini for each site.
Regarding the content of the script and what to do with the information you are free to do whatever you want with that script. The pro is that you don’t have to modify any file and this will be executed for any php page your server is serving