PHP错误:open_basedir限制生效

时间:2013-01-22 18:09:07

标签: php require-once open-basedir

我使用这个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)不在允许范围内   path(s):( / var / www / hmci / data:。)in   第2行的/var/www/hmci/data/www/hmci.ru/php-yubico/test.php警告:   require_once(/usr/share/php/Auth/Yubico.php):无法打开流:   不允许进行操作   第2行的/var/www/hmci/data/www/hmci.ru/php-yubico/test.php致命   错误:require_once():无法打开所需的'Auth / Yubico.php'   (include_path ='。:/ usr / share / php:/ usr / share / pear')in   第2行的/var/www/hmci/data/www/hmci.ru/php-yubico/test.php

如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

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()方法)。

答案 1 :(得分:1)

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

require_once dirname(__FILE__) . '/Auth/Yubico.php';
相关问题