PHP 错误:open_basedir 限制生效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14465212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:19:31  来源:igfitidea点击:

PHP error: open_basedir restriction in effect

phprequire-onceopen-basedir

提问by Anton

I using this Yubico authentication PHP class: https://github.com/Yubico/php-yubico. I create php file test.php with this code:

我使用这个 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!";
 }
?>

And do all instructions in this github library. When I open this script I get:

并执行此 github 库中的所有说明。当我打开这个脚本时,我得到:

Warning: require_once(): open_basedir restriction in effect. File(/usr/share/php/Auth/Yubico.php) is not within the allowed path(s): (/var/www/hmci/data:.) in /var/www/hmci/data/www/hmci.ru/php-yubico/test.php on line 2 Warning: require_once(/usr/share/php/Auth/Yubico.php): failed to open stream: Operation not permitted in /var/www/hmci/data/www/hmci.ru/php-yubico/test.php on line 2 Fatal error: require_once(): Failed opening required 'Auth/Yubico.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/hmci/data/www/hmci.ru/php-yubico/test.php on line 2

警告: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 行

How to solve this problem?

如何解决这个问题呢?

回答by helmbert

open_basediris a PHP option restricting PHP's access to specific directories.

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

You have the directory /usr/share/phpin your include path without having access to it. Usually, PHP tries all paths in the include_pathone by one. This means that PHP cannot find the file Auth/Yubico.phpin the current directory, so PHP searches in /usr/share/phpnext.

/usr/share/php在包含路径中拥有该目录而无法访问它。通常,PHP 会include_path一一尝试所有路径。这意味着 PHP 无法Auth/Yubico.php在当前目录中找到该文件,因此 PHP 在/usr/share/phpnext 中搜索。

Make sure that the file you want to include is actually there. You can also remove /usr/share/phpfrom your include path (either by editing the php.inifile, if you have access to it, otherwhise using the ini_set()method).

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

回答by Nick Ciske

Using an explicit path to the file you want to include causes PHP to skip the directory scanning causing the error:

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

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