【问题标题】:PHP error: open_basedir restriction in effectPHP 错误:open_basedir 限制生效
【发布时间】:2013-01-06 01:49:49
【问题描述】:

我使用这个 Yubico 认证 PHP 类:https://github.com/Yubico/php-yubico。我用这段代码创建了 php 文件 test.php:

<?php
 require_once 'Auth/Yubico.php';
 $otp = "ccbbddeertkrctjkkcglfndnlihhnvekchkcctif";

 # Generate a new id+key from https://api.yubico.com/get-api-key/
 $yubi = new Auth_Yubico('42', 'FOOBAR=');
 $auth = $yubi->verify($otp);
 if (PEAR::isError($auth)) {
    print "<p>Authentication failed: " . $auth->getMessage();
    print "<p>Debug output from server: " . $yubi->getLastResponse();
 } else {
    print "<p>You are authenticated!";
 }
?>

并在这个 github 库中执行所有指令。当我打开这个脚本时,我得到:

警告:require_once():open_basedir 限制生效。 文件(/usr/share/php/Auth/Yubico.php)不在允许范围内 路径:(/var/www/hmci/data:.)在 /var/www/hmci/data/www/hmci.ru/php-yubico/test.php 在第 2 行警告: require_once(/usr/share/php/Auth/Yubico.php):无法打开流: 不允许操作 /var/www/hmci/data/www/hmci.ru/php-yubico/test.php 在第 2 行致命 错误:require_once():无法打开所需的“Auth/Yubico.php” (include_path='.:/usr/share/php:/usr/share/pear') 在 /var/www/hmci/data/www/hmci.ru/php-yubico/test.php 在第 2 行

如何解决这个问题?

【问题讨论】:

    标签: php require-once open-basedir


    【解决方案1】:

    open_basedir 是一个 PHP 选项,用于限制 PHP 对特定目录的访问。

    您的包含路径中有目录/usr/share/php,但无法访问它。通常,PHP 会一一尝试include_path 中的所有路径。这意味着PHP在当前目录下找不到文件Auth/Yubico.php,所以PHP在/usr/share/php下搜索。

    确保您要包含的文件确实存在。你也可以从你的包含路径中删除/usr/share/php(或者通过编辑php.ini文件,如果你可以访问它,或者使用ini_set()方法)。

    【讨论】:

    • 但是如果这个文件在 /usr/share/php 目录下呢?我认为这个类需要 PEAR,我通过 PEAR 安装了这个库。我认为这个文件在 /usr/share/php.
    • 您也可以尝试将/usr/share/php 添加到您的open_basedir 配置指令中。
    【解决方案2】:

    使用要包含的文件的显式路径会导致 PHP 跳过导致错误的目录扫描:

    require_once dirname(__FILE__) . '/Auth/Yubico.php';
    

    【讨论】:

      猜你喜欢
      • 2011-03-16
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      相关资源
      最近更新 更多