在其他任何事情之前自动为所有页面加载 config.php 文件 [英] Automatically load a config.php file for all pages before anything else

查看:17
本文介绍了在其他任何事情之前自动为所有页面加载 config.php 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何设置一个特定文件可以先自动为所有页面加载的东西?

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 文件中,但不带 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 中,您可以将此行添加到 location ~ .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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆