PHP 使用 .htaccess 时重新声明错误 auto_prepend_file
PHP Redeclare error when using .htaccess auto_prepend_file
我有一个名为 config.php
的文件,我在其中使用 require_once
包含了具有函数的不同文件。
当我尝试使用存储在项目根目录中的 .htaccess
自动添加 config.php
时,我在每个包含函数的文件中都收到重新声明错误。
有没有办法解决这个问题或包含 config.php
而不会出现此错误?
好的,我想出了一个使用 foreach
和 glob
的解决方案。我不知道它是否有效,但它似乎有效。
// Include all files in X directory
foreach (glob('X\*.php') as $file)
{
$script = basename($_SERVER['SCRIPT_NAME']);
$filename = basename($file);
if ($script != $filename)
{
include_once $file;
}
}
此代码在自动前置文件中。
我有一个名为 config.php
的文件,我在其中使用 require_once
包含了具有函数的不同文件。
当我尝试使用存储在项目根目录中的 .htaccess
自动添加 config.php
时,我在每个包含函数的文件中都收到重新声明错误。
有没有办法解决这个问题或包含 config.php
而不会出现此错误?
好的,我想出了一个使用 foreach
和 glob
的解决方案。我不知道它是否有效,但它似乎有效。
// Include all files in X directory
foreach (glob('X\*.php') as $file)
{
$script = basename($_SERVER['SCRIPT_NAME']);
$filename = basename($file);
if ($script != $filename)
{
include_once $file;
}
}
此代码在自动前置文件中。