How to include a php script in all HTTP requests coming to the server
I have a file called init.php
which I want to get automatically included in each and every HTTP request coming to my server. My server is on LAMP configuration with PHP 5.3 and fast CGI. Any method to achieve this is welcome.
What I have already tried:
I have already tried the auto_prepend_file
method with .htaccess
file but no success.
I have done the following.
.htaccess
File:
php_value auto_prepend_file /home/user/domain.com/init.php
init.php
file:
<?php
echo "statement 2";
?>
index.php
file:
statement 1
So, now if I visit http://domain.com/ I find only statement 1 getting printed. statement 2 is not getting printed.
Kindly le开发者_StackOverflowt me know how to correct this or if there is any other way to achieve this.
My server is on LAMP configuration with PHP 5.3 and fast CGI.
You can not set PHP ini directives with the .htaccess
method with FCGI/CGI. You need to apply the changes within the php.ini or better the user ini files Docs instead.
Place a file called .user.ini
into the document root and add the auto_prepend_file
Docs directive in there:
auto_prepend_file = /home/user/domain.com/init.php
This should do the job for you.
My server is on LAMP configuration with PHP 5.3 and fast CGI.
fast CGI means no .htaccess directive would work. Change your php.ini instead.
automatically included in each and every HTTP request
with auto_prepend_file you obviously can't include a php file to "each and every HTTP request", but to requests routed to PHP files only.
精彩评论