Re: Fatal error

TaMeR <[email protected]> Fri, 30 Dec 2005 13:09:03 -0500
Newsgroups gmane.comp.php.pear.liveuser
Message-ID <[email protected]>

You are right Michiel the config is probably where the problem is. I 
just can't get my head wrapped around that.
Here it is:

<?php

// BC hack
if (!defined('PATH_SEPARATOR')) {
     if (defined('DIRECTORY_SEPARATOR') && DIRECTORY_SEPARATOR == "\\") {
         define('PATH_SEPARATOR', ';');
     } else {
         define('PATH_SEPARATOR', ':');
     }
}

error_reporting(E_ALL);

// right definitions
define('ACCESS', 1);
define('READ_TESTS', 2);
define('WRITE_TESTS', 3);

// set this to the path in which the directory for liveuser resides
// more remove the following two lines to test LiveUser in the standard
// PEAR directory
//$path_to_liveuser_dir = './pear/'.PATH_SEPARATOR;
//ini_set('include_path', $path_to_liveuser_dir.ini_get('include_path'));

// Data Source Name (DSN)
$db_user = 'admin';
$db_pass = '****';
$db_host = 'localhost';
$db_name = 'luadmin3';
$dsn = "mysql://$db_user:$db_pass@$db_host/$db_name";



$liveuserConfig = array(
     'session'           => array('name' => 'PHPSESSID','varname' => 
'loginInfo'),
     'logout'            => array('destroy'  => true),
     'cookie'            => array(
         'name' => 'loginInfo',
         'path' => null,
         'domain' => null,
         'secure' => false,
         'lifetime' => 30,
         'secret' => 'mysecretkey',
         'savedir' => '.',
     ),
     'authContainers'    => array(
         'DB' => array(
             'type'          => 'MDB2',
             'expireTime'   => 0,
             'idleTime'     => 0,
             'allowDuplicateHandles'  => 1,
             'passwordEncryptionMode' => 'PLAIN',
             'storage' => array(
                 'dsn' => $dsn,
                 'alias' => array(
                     'auth_user_id' => 'authuserid',
                     'lastlogin' => 'lastlogin',
                     'is_active' => 'isactive',
                 ),
                 'fields' => array(
                     'lastlogin' => 'timestamp',
                     'is_active' => 'boolean',
                 ),
                 'tables' => array(
                     'users' => array(
                         'fields' => array(
                             'lastlogin' => false,
                             'is_active' => false,
                         ),
                     ),
                 ),
             )
         )
     ),
     'permContainer' => array(
         'type'  => 'Medium',
         'alias' => array(),
         'storage' => array(
             'MDB2' => array(
                 'dsn' => $dsn,
                 'prefix' => 'liveuser_',
                 'tables' => array(),
                 'fields' => array(),
             ),
         ),
     ),
);

// Get LiveUser class definition
require_once 'LiveUser.php';

// The error handling stuff is not needed and used only for debugging
// while LiveUser is not yet mature
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'eHandler');

function eHandler($errObj)
{
     echo('<hr /><span style="color: red;">' . $errObj->getMessage() . 
':<br />' . $errObj->getUserInfo() . '</span><hr />');
     $debug_backtrace = debug_backtrace();
     array_shift($debug_backtrace);
     $message= 'Debug backtrace:'."\n";

     foreach ($debug_backtrace as $trace_item) {
         $message.= "\t" . '    @ ';
         if (array_key_exists('file', $trace_item)) {
             $message.= basename($trace_item['file']) . ':' . 
$trace_item['line'];
         } else {
             $message.= '- PHP inner-code - ';
         }
         $message.= ' -- ';
         if (array_key_exists('class', $trace_item)) {
             $message.= $trace_item['class'] . $trace_item['type'];
         }
         $message.= $trace_item['function'];

         if (array_key_exists('args', $trace_item) && 
is_array($trace_item['args'])) {
             $message.= '('.@implode(', ', $trace_item['args']).')';
         } else {
             $message.= '()';
         }
         $message.= "\n";
     }
     echo "<pre>$message</pre>";
}

// Create new LiveUser object
$LU =& LiveUser::factory($liveuserConfig);

if (!$LU->init()) {
     var_dump($LU->getErrors());
     die();
}

$handle = (array_key_exists('handle', $_REQUEST)) ? $_REQUEST['handle'] 
: null;
$passwd = (array_key_exists('passwd', $_REQUEST)) ? $_REQUEST['passwd'] 
: null;
$logout = (array_key_exists('logout', $_REQUEST)) ? $_REQUEST['logout'] 
: false;
$remember = (array_key_exists('rememberMe', $_REQUEST)) ? 
$_REQUEST['rememberMe'] : false;
if ($logout) {
     $LU->logout(true);
} elseif(!$LU->isLoggedIn() || ($handle && $LU->getProperty('handle') != 
$handle)) {
     if (!$handle) {
         $LU->login(null, null, true);
     } else {
         $LU->login($handle, $passwd, $remember);
     }
}

require_once 'LiveUser/Admin.php';

$luadmin =& LiveUser_Admin::factory($liveuserConfig);
$luadmin->init();

$language_selected = array_key_exists('language', $_GET) ? 
$_GET['language'] : 'de';
?>


Michiel Nugter wrote:
> Hello Tamer,
> 
> As far as I can see it should work fine.
> 
> Just a couple of ideas that could be the problem here.
> 
> Is your liveuser config array correctly formed?
> Are the Liveuser_Admin->perm and Liveuser->auth object set?
> Does the $admin variable contain a proper LUA object?
> 
> 
> 
> Kind Regards,
> 
> 
> Michiel Nugter
> Dinnersite.nl
> 
> 
> 
> 
> TaMeR wrote:
> 
>>
>> Hello
>>
>> Still new to this and was wondering after hours of testing if someone 
>> could give me a hint on this. Thank you
>>
>> Dennis Kaplan
>>
>> ** ERROR **
>>
>> Fatal error: Call to a member function on a non-object in ...
>> on line: $user_id = $admin->addUser($data, $level);
>>
>> ** INFO **
>> I am using the admin example 3 and I have added a email field to the 
>> mySQL DB
>>
>> ** CODE **
>> <?php
>> if (isset($_POST['submit'])) {
>>     $data = array(
>>         'handle'    => $_REQUEST['handle'],
>>         'email'        => $_REQUEST['email'],
>>         'passwd'    => $_REQUEST['passwd']
>>     );
>>     $level = 1;
>>     $user_id = $admin->addUser($data, $level);
>> }
>>
>> ?>
>> <form method="post">
>>     <input type="text" name="handle" size="6" maxlength="80">
>>     <input type="text" name="email" size="10" maxlength="80">
>>     <input type="password" name="passwd" size="6" maxlength="80">
>>     <input name="submit" type="submit" value="Submit">
>> </form><br />