PHP error: open_basedir restriction in effect

余生颓废 提交于 2019-12-23 02:48:14

问题


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

<?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:

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

How to solve this problem?


回答1:


open_basedir is a PHP option restricting PHP's access to specific directories.

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

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




回答2:


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

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


来源:https://stackoverflow.com/questions/14465212/php-error-open-basedir-restriction-in-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!