在其他任何页面之前自动加载所有页面的config.php文件 [英] Automatically load a config.php file for all pages before anything else
问题描述
有没有人知道如何设置可以在所有页面之前自动加载特定文件的内容?
Does anyone know how to set up something where a specific file can be loaded automatically for all pages before anything else?
例如,如果我有 config.php
文件,我想在任何人访问我网站上的页面时加载此文件。
For example if I have a config.php
file and I want this file to be loaded anytime anyone visits a page on my website.
在这里我会有一些配置信息需要在其他任何内容之前加载。
In here I would have some configuration info that is required to load prior to anything else.
我不喜欢我想在另一个php文件上做任何包含,我只想在每次其他任何时候自动加载它。基本上是一个通用的包含。
I don't want to do any includes on another php file for this I just want this to be loaded every time automatically before anything else. Basically a universal include.
推荐答案
你想使用auto_prepend_file 。在php.ini或.htaccess文件中将此指令设置为 config.php
文件的路径,访问的任何PHP文件都将自动将配置文件的内容添加到它。
You want to use auto_prepend_file. Set this directive in your php.ini or .htaccess file to the path to your config.php
file and any PHP file accessed will automatically have the contents of the config file prepended to it.
对于 .htaccess
:
php_value auto_prepend_file /full/path/to/file/config.php
请记住,这只适用于PHP作为Apache模块运行的服务器。如果PHP作为CGI运行,您需要在 php.ini
文件中添加编辑或将其放在 .user.ini $中c $ c>文件没有
php_value
部分。
Keep in mind this ONLY will work on a server where PHP is run as an Apache module. If PHP is run as a CGI you need to add edit it in your php.ini
file or put it inside a .user.ini
file just without the php_value
part.
在 Nginx
您可以将此行添加到位置内的服务器配置〜\.php $
In Nginx
you could add this line to server configuration inside location ~ \.php$
fastcgi_param PHP_VALUE "auto_prepend_file=/full/path/to/file/config.php";
这篇关于在其他任何页面之前自动加载所有页面的config.php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!