| View previous topic :: View next topic |
| Author |
Message |
faust
Joined: 17 Jul 2008 Posts: 7
|
Posted: Thu Jul 17, 2008 3:56 pm Post subject: Trouble with pear::auth and pear::mdb2 |
|
|
I want create simple authentication system, but I have small problem. When I am using Array container everything is OK, but whe I migrate to MDB2 I cannot login. Login data is corrent. This is a code
| Code: |
<?php
require_once(realpath(dirname(__FILE__).'/../'.DIR_LIB_3RDPARTY.'Auth.php'));
require_once(realpath(dirname(__FILE__).'/../'.DIR_LIB_3RDPARTY.'MDB2.php'));
require_once(realpath(dirname(__FILE__).'/../'.DIR_LIB_CORE.'mySmarty.class.php'));
session_start();
$akcja = 1;
$options = array(
'enableLogging' => true,
'cryptType' => '',
'dsn' => 'mysqli://thedrx_faust:wsxokmR1@localhost/thedrx_faust',
'table' => 'lechia_users',
'usernamecol' => 'username',
'passwordcol' => 'password'
);
$a = new Auth('MDB2', $options);
$a->setShowLogin(false);
$a->start();
$s = new mySmarty;
if($a->checkAuth()) {
if((isset($_GET['login'])) && ($_GET['login'] == 4)) {
$a->logout();
session_unset();
$akcja = 3;
}
elseif(count($_GET['login']) == 0) {
$akcja = 2;
$_SESSION['login'] = $akcja;
}
else {
$a->logout();
session_unset();
$akcja = 1;
}
}
else {
if($a->getStatus() == AUTH_WRONG_LOGIN) {
$username = '';
if(isset($_POST['username'])) {
$username = preg_replace('/[^a-z0-9]/', '', $_POST['username']);
$s->assign('username', $username);
}
$s->assign('auth_wrong_login', true);
}
}
$s->assign('akcja', $akcja);
$s->display('login.tpl');
?>
|
Please help |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 911
|
Posted: Thu Jul 17, 2008 4:35 pm Post subject: |
|
|
Most likely an include_path issue => MDB2 can't find its own files.
Your require_once calls should like this for PEAR packages:
| Code: |
require_once 'Auth.php';
require_once 'MDB2.php';
|
|
|
| Back to top |
|
 |
faust
Joined: 17 Jul 2008 Posts: 7
|
Posted: Thu Jul 17, 2008 5:55 pm Post subject: |
|
|
| Include path is correct. I've got PEAR packages in different place |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 911
|
|
| Back to top |
|
 |
faust
Joined: 17 Jul 2008 Posts: 7
|
Posted: Thu Jul 17, 2008 6:41 pm Post subject: |
|
|
I add logging and I have really strange output. Both PEAR_LOG_INFO and PEAR_LOG_DEBUG are empty!
For sure I present my file tree:
/
|---index.php(which includes source file)
|---action
|--------action/login.php (the source file)
|---lib
|-------lib/3rdparty
|-----------lib/3rdparty/Auth
|-----------------lib/3rdparty/Auth/Auth
|---------------------lib/3rdparty/Auth/Auth/Auth.php
|------------lib/3rdparty/MDB2
|----------------lib/3rdparty/MDB2/MDB2
|---------------------lib/3rdparty/MDB2/MDB2/MDB2.php
|------------lib/3rdparty/Smarty
|----------------lib/3rdparty/Smarty/templates
|---------------------lib/3rdparty/Smarty/templates/login.tpl (which is used by source file) |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 911
|
Posted: Thu Jul 17, 2008 11:06 pm Post subject: |
|
|
You need the Log package from PEAR, otherwise logging won't work. If you add the following four lines to the beginning of your script, you might get more helpful error messages:
| Code: |
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'PEAR.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
|
The directory structure isn't right. The directories Auth and MDB2 should be located next to each other, and directly contain the other files and subdirectories. A subdirectory with the same name is wrong.
For MDB2 you'll also need a driver package (e.g. MDB2_Driver_mysql) installed in a subdirectory of the MDB2 directory.
MDB2.php must not be in the MDB2 directory, but in the parent directory. And the include_path needs to point to this parent directory. |
|
| Back to top |
|
 |
faust
Joined: 17 Jul 2008 Posts: 7
|
Posted: Fri Jul 18, 2008 1:08 am Post subject: |
|
|
I tried to correct my code and file structure.Ofcourse it doesn't work. Here you go the source:
| Code: |
<?php
require_once(realpath(dirname(__FILE__).'/../lib/3rdparty/Smarty/Smarty.class.php'));
require_once(realpath(dirname(__FILE__).'/../lib/3rdparty/Auth.php'));
require_once(realpath(dirname(__FILE__).'/../lib/3rdparty/MDB2.php'));
require_once(realpath(dirname(__FILE__).'/../lib/3rdparty/Log.php'));
require_once(realpath(dirname(__FILE__).'/../lib/3rdparty/Log/Log/observer.php'));
$smarty = new Smarty;
$smarty->template_dir = (realpath(dirname(__FILE__)).'/../lib/3rdparty/Smarty/templates/');
$smarty->compile_dir = (realpath(dirname(__FILE__)).'/../lib/3rdparty/Smarty/templates_c/');
class Auth_Log_Observer extends Log_observer {
var $messages = array();
function notify($event) {
$this->messages[] = $event;
}
}
$options = array(
'dsn' => 'mysqli://thedrx_faust:wsxokmR1',
'table' => 'gomze_users',
'usernamecol' => 'username',
'passwordcol' => 'password'
);
$loginAction = 1;
$auth = new Auth('MDB2', $options);
$auth->setShowLogin(false);
$infoObserver = new Auth_Log_Observer(PEAR_LOG_INFO);
$auth->attachLogObserver($infoObserver);
$debugObserver = new Auth_Log_Observer(PEAR_LOG_DEBUG);
$auth->attachLogObserver($debugObserver);
$auth->start();
if($auth->checkAuth()) {
if((isset($_GET['id'])) && ($_GET['id'] == 4)) {
$auth->logout();
session_unset();
$loginAction = 3;
}
if(count($_GET) == 1) {
$loginAction = 2;
}
else {
$auth->logout();
session_unset();
$loginAction = 1;
}
}
else {
if($auth->getStatus() == AUTH_WRONG_LOGIN) {
$username = '';
if(isset($_POST['username'])) {
$username = preg_replace('/[a-z0-9]/', '', $_POST['username']);
$smarty->assign('username', $username);
}
$smarty->assign('auth_wrong_login', true);
}
$loginAction = 1;
}
print '<h3>Logging Output:</h3>'
.'<b>PEAR_LOG_INFO level messages:</b><br/>';
foreach ($infoObserver->messages as $event) {
print $event['priority'].': '.$event['message'].'<br/>';
}
print '<br/>'
.'<b>PEAR_LOG_DEBUG level messages:</b><br/>';
foreach ($debugObserver->messages as $event) {
print $event['priority'].': '.$event['message'].'<br/>';
}
$smarty->assign('loginAction', $loginAction);
$smarty->display('login.tpl');
?>
|
And here is file structure
/
|----index.php(which include source file)
|----action/
|---------action/login.php (source file)
|----lib/
|-------lib/3rdparty
|-----------lib/3rdparty/Auth.php
|-----------lib/3rdparty/MDB2.php
|-----------lib/3rdparty/Log.php
|---------------lib/3rdparty/Auth/
|-------------------lib/3rdparty/Auth/Auth/
|-----------------------lib/3rdparty/Auth/Auth/Anonymous.php
|-----------------------lib/3rdparty/Auth/Auth/Auth.php
|-----------------------lib/3rdparty/Auth/Auth/Controller.php
|-------------------lib/3rdparty/Auth/Container
|-----------------------lib/3rdparty/Auth/Container/MDB2.php
|---------------lib/3rdparty/MDB2/
|-------------------lib/3rdparty/MDB2/Date.php
|-------------------lib/3rdparty/MDB2/Extended.php
|-------------------lib/3rdparty/MDB2/Iterator.php
|-------------------lib/3rdparty/MDB2/LOB.php
|-------------------lib/3rdparty/MDB2/Driver/
|-----------------------lib/3rdparty/MDB2/Driver/mysqli.php
|-----------------------lib/3rdparty/MDB2/Driver/Datatype/
|---------------------------lib/3rdparty/MDB2/Driver/Datatype/Common.php
|---------------------------lib/3rdparty/MDB2/Driver/Datatype/mysqli.php
|-----------------------lib/3rdparty/MDB2/Driver/Function/
|---------------------------lib/3rdparty/MDB2/Driver/Function/Common.php
|---------------------------lib/3rdparty/MDB2/Driver/Function/mysqli.php
|-----------------------lib/3rdparty/MDB2/Driver/Manager/
|---------------------------lib/3rdparty/MDB2/Driver/Manager/Common.php
|---------------------------lib/3rdparty/MDB2/Driver/Manager/mysqli.php
|-----------------------lib/3rdparty/MDB2/Driver/Native/
|---------------------------lib/3rdparty/MDB2/Driver/Native/Common.php
|---------------------------lib/3rdparty/MDB2/Driver/Native/mysqli.php
|-----------------------lib/3rdparty/MDB2/Driver/Reverse/
|---------------------------lib/3rdparty/MDB2/Driver/Reverse/Common.php
|---------------------------lib/3rdparty/MDB2/Driver/Reverse/mysqli.php
|---------------lib/3rdparty/Log/
|-------------------lib/3rdparty/Log/Log/
|-----------------------lib/3rdparty/Log/Log/composite.php
|-----------------------lib/3rdparty/Log/Log/console.php
|-----------------------lib/3rdparty/Log/Log/deamon.php
|-----------------------lib/3rdparty/Log/Log/display.php
|-----------------------lib/3rdparty/Log/Log/error_log.php
|-----------------------lib/3rdparty/Log/Log/file.php
|-----------------------lib/3rdparty/Log/Log/firebug.php
|-----------------------lib/3rdparty/Log/Log/mail.php
|-----------------------lib/3rdparty/Log/Log/mcal.php
|-----------------------lib/3rdparty/Log/Log/mdb2.php
|-----------------------lib/3rdparty/Log/Log/null.php
|-----------------------lib/3rdparty/Log/Log/observer.php
|-----------------------lib/3rdparty/Log/Log/sql.php
|-----------------------lib/3rdparty/Log/Log/sqlite.php
|-----------------------lib/3rdparty/Log/Log/syslog.php
|-----------------------lib/3rdparty/Log/Log/win.php
|-----------------------lib/3rdparty/Smarty/
|---------------------------lib/3rdparty/Smarty/Smarty.class.php
|---------------------------lib/3rdparty/Smarty/templates/
|---------------------------lib/3rdparty/Smarty/templates_c/
Logging output is still empty. I'm sorry for log listings. Plese help me
//Edit
It's really path include problem. I've create serv on my localhost install PEAR and it works. I will ask in installation section. Please close. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 911
|
Posted: Fri Jul 18, 2008 3:13 pm Post subject: |
|
|
| Well, you're still using the likely wrong require_once calls, and you still haven't added the debug lines that I've mentioned. Both things will help you to debug your problem. |
|
| Back to top |
|
 |
|