Php 注意使用pearauth
我正在尝试使用pearauth进行php站点身份验证。我遵循了官方文档中的示例,但我无法摆脱很多通知警报,比如:Php 注意使用pearauth,php,authentication,pear,Php,Authentication,Pear,我正在尝试使用pearauth进行php站点身份验证。我遵循了官方文档中的示例,但我无法摆脱很多通知警报,比如: Notice: Constant DB_OK already defined in /usr/share/php/DB.php on line 47 Call Stack: 0.0005 647400 1. {main}() /var/www/concursosRep/admin/index.php:0 0.0751 7100160 2. include('/var/www/conc
Notice: Constant DB_OK already defined in /usr/share/php/DB.php on line 47
Call Stack:
0.0005 647400 1. {main}() /var/www/concursosRep/admin/index.php:0
0.0751 7100160 2. include('/var/www/concursosRep/admin/loginbeta.php') /var/www/concursosRep/admin/index.php:60
0.0788 7448160 3. Auth->start() /var/www/concursosRep/admin/loginbeta.php:114
0.0790 7448528 4. Auth->login() /usr/share/php/Auth.php:528
0.0790 7448608 5. Auth->_loadStorage() /usr/share/php/Auth.php:546
0.0790 7448608 6. Auth->_factory() /usr/share/php/Auth.php:445
0.0809 7681728 7. include_once('/usr/share/php/Auth/Container/DB.php') /usr/share/php/Auth.php:468
0.0839 8066384 8. require_once('/usr/share/php/DB.php') /usr/share/php/Auth/Container/DB.php:32
0.0869 8374552 9. define() /usr/share/php/DB.php:47
我知道,这意味着在某种程度上,该库不止一次被包括在内,但我不知道如何修复它。在我的php.ini中,包含以下路径:
include_path .:/usr/share/php:/usr/share/php/libzend-framework-php
我首先想到的问题是Zend在某处加载了pear auth的类,所以我将include_路径改为:.:/usr/share/php,但我有同样的问题
以下是我如何使用它:
require_once ('Auth.php');//Pear Auth
$dns = 'mysql://'.USER.':'.Util::decodePass(PASSWORD).'@'.SERVER.'/'.DBNAME;
$options = array(
'dsn' => $dns,
'table' => 'usuario',
'usernamecol' => 'login',
'passwordcol' => 'password',
'cryptType' => 'md5', //'sha1'
'db_fields' => '*'
);
// Create the Auth object:
$auth = new Auth('DB', $options, 'show_login_form');
// Start the authorization:
$auth->start();
// Confirm authorization:
if ($auth->checkAuth()) {
//Authorized
echo(javaScriptRedirect(true,$js));
} else { // Unauthorized.
echo(javaScriptRedirect(false,$js));
}
我试图在我的系统中找到两个文件DB.php
;以下是我得到的:
# sudo find -name DB.php -print
./usr/share/php/DB.php
./usr/share/php/Auth/Container/DB.php
#var_dump(get_included_files());
string(23) "/usr/share/php/Auth.php" [30] => string(36) "/usr/share/php/Auth/Container/DB.php" [31] => string(33) "/usr/share/php/Auth/Container.php" [32] => string(21) "/usr/share/php/DB.php" [33] => string(23) "/usr/share/php/PEAR.php" [34] => string(24) "/usr/share/php/PEAR5.php" [35] => string(27) "/usr/share/php/DB/mysql.php" [36] => string(28) "/usr/share/php/DB/common.php" }
我试图在我的脚本中找到重复的文件,以下是我得到的:
# sudo find -name DB.php -print
./usr/share/php/DB.php
./usr/share/php/Auth/Container/DB.php
#var_dump(get_included_files());
string(23) "/usr/share/php/Auth.php" [30] => string(36) "/usr/share/php/Auth/Container/DB.php" [31] => string(33) "/usr/share/php/Auth/Container.php" [32] => string(21) "/usr/share/php/DB.php" [33] => string(23) "/usr/share/php/PEAR.php" [34] => string(24) "/usr/share/php/PEAR5.php" [35] => string(27) "/usr/share/php/DB/mysql.php" [36] => string(28) "/usr/share/php/DB/common.php" }
希望有人能帮忙找出问题所在。
注意。注1:Pear DB是一个不推荐使用的库,因此您应该将Auth配置为使用MDB2 注2:这是一个通知,因此您的代码可以正常工作 根据您提供的信息,很难判断DB_OK常量之前是在哪里定义的。要做到这一点,需要完整的代码 要调试这样的错误,您可以学习使用XDEBUG并逐步运行代码。 或者,如果你不想像专业人士那样学习和做这件事,这里有一些关于如何找到它的丑陋想法: 将此放在代码的最开头:
declare(ticks=1);
function my_tick_function()
{
if (defined('DB_OK'))
{
echo 'DB_OK defined for the first time as ' . DB_OK;
var_dump(debug_backtrace());
unregister_tick_function('my_tick_function');
}
}
// using a function as the callback
register_tick_function('my_tick_function', true);
(我没有运行它,它只是一个想法)
我不认为
DB.php
会被加载两次,因为这样你会得到一个关于已经定义的类的致命错误,而不仅仅是一个常量
如果我是你,我会grep
调用DB_OK
和定义调用的代码。若要将选择限制为某些文件,请添加
var_dump(get_included_files());
在第47行的/usr/share/php/DB.php中。它将向您显示哪些文件已经包含,因此define()
调用需要在其中
另一种方法是使用日志记录正在进行的define()
调用。如果您安装了xdebug,这可能是最简单的解决方案。我试图在我的系统中找到两个文件DB.php这里是我得到的:sudo find-name DB.php-print./usr/share/php/DB.php./usr/share/php/Auth/Container/DB.phpdes您的代码定义DB_OK
?感谢您的帮助@cweiske我没有在代码中定义那个常量。我只粘贴了一个通知,但所有常量都有相同的警告通知,因此我认为Entrie PEAR加载了不止一次。我从命令行安装了PEAR,这可能很重要。调试时使用get_included_files()解决了我的另一个问题,+1!