Reputation: 3842
I am trying to use PEAR Auth for a php site authentication. I followed the examples in the official documentation but I can not get rid of a lot of notice alerts like this one:
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
I know that it means that in some way the library was included more than once but I do not know how to fix it. In my php.ini I have this in include_path:
include_path .:/usr/share/php:/usr/share/php/libzend-framework-php
I first thought that the problem was that Zend was loading the pear auth's class in somewhere so I changed the include_path to: .:/usr/share/php but I have the same problem.
Here is how I am using it:
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));
}
I tried to find two files DB.php
in my system; here is what I got:
# sudo find -name DB.php -print
./usr/share/php/DB.php
./usr/share/php/Auth/Container/DB.php
I tried to find duplicate files includes in my script, here is what I got:
#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" }
Hope someone can help to figure out what the problem may be. Regards.
Upvotes: 4
Views: 1066
Reputation: 3695
note1: Pear DB is a deprecated library so you should configure Auth to use MDB2 !
note2: It is a notice so you code could be working well.
With info you have given it is hard to tell where the DB_OK constant was defined previously. To do this one would require the full code.
To debug errors like this you could learn to use XDEBUG and run the code step by step. Or if you don't want to learn and do this like a pro, here is some ugly idea on how you can find it:
Put this at the very beginning of your code:
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);
(i have not run it, it is just an idea)
http://php.net/manual/en/function.register-tick-function.php
Upvotes: 1
Reputation: 31088
I don't think that DB.php
gets loaded twice, because then you'd get a fatal error about a class being already defined - not only a constant.
If I were you, I'd grep
the code for DB_OK
and define
calls. To limit the choice to some files, add a
var_dump(get_included_files());
in /usr/share/php/DB.php
on line 47. It will show you which files have been included already, and thus the define()
call needs to be in them.
An alternative is to use xdebug's function traces to log where define()
calls are being made. This is probably the most easy solution if you have xdebug installed.
Upvotes: 1