【问题标题】:PHP Redeclare error when using .htaccess auto_prepend_file使用 .htaccess auto_prepend_file 时 PHP 重新声明错误
【发布时间】:2016-12-14 15:55:21
【问题描述】:

我有一个名为config.php 的文件,其中我使用require_once 包含了带有函数的不同文件。 当我尝试使用存储在项目根目录中的 .htaccess 自动添加 config.php 时,我在每个包含函数的文件中都会收到重新声明错误。

有没有办法解决此问题或包含config.php 而不会出现此错误?

【问题讨论】:

    标签: php apache .htaccess mysqli wamp


    【解决方案1】:

    好的,我想出了一个使用foreachglob 的解决方案。我不知道它是否有效,但它似乎有效。

    // 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;
        }
    }
    

    此代码在自动前置文件中。

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 1970-01-01
      • 2013-02-25
      • 2011-09-12
      • 2017-05-22
      • 1970-01-01
      • 2010-10-17
      • 2014-11-07
      • 1970-01-01
      相关资源
      最近更新 更多