开发者

php, apache & .htaccess: include php configuration file globally

i have a php project which has a configuration file config.php that stores config information like database info, directories, etc.

normally we would include this config file at the top of every php page like require_once(".../config.php); however, i have found a way to do this by creating a .htaccess file and include this:

php_value  auto_prepend_file  /home/public_开发者_Go百科html/..../config.php

this works fine until i transferred it to the shared hosting. apparently, this shared hosting allows us to change the PHP version from 4x to 5x. After changing to 5x, i realised they have created a .htaccess file with the following content:

<FilesMatch "\.php$"> # phpvs v5
AddHandler x-httpd-php5 .php # phpvs v5
</FilesMatch> # phpvs v5

with this, it ignores the include path to the config file.. how can i go about fixing this? i certainly do not wanna include my config.php in every php files.


An htaccess file is not restricted to containing a single directive. You can have both.


normally we would include this config file at the top of every php page like require_once(".../config.php); however, i have found a way to do this by creating a .htaccess file and include this

Probably not the wisest move. It is more stable and portable to do this in your PHP than to rely on .htaccess. Relying on .htaccess means if your web server is changed or reconfigured it's likely to stop working (as you found).

I know it doesn't answer your question but I would consider going back to doing this using require_once() in the appropriate PHP files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜