PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Auth 1.5.1 , error handling etc

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Authentication
View previous topic :: View next topic  
Author Message
MaxT



Joined: 17 May 2007
Posts: 4

PostPosted: Thu May 17, 2007 3:46 pm    Post subject: Auth 1.5.1 , error handling etc Reply with quote

I'm new to PEAR and after having a look at the Auth package have a few questions.

1.

When using the constructor, something like;

$auth = new Auth(...);

Do you need to wrap in a try / catch block?


Looking at the code in Auth.php there is a possible Exception (throwError), but this is not documented.

Code:




    /**
     * Constructor
     *
     * Set up the storage driver.
     *
     * @param string    Type of the storage driver
     * @param mixed     Additional options for the storage driver
     *                  (example: if you are using DB as the storage
     *                   driver, you have to pass the dsn string here)
     *
     * @param string    Name of the function that creates the login form
     * @param boolean   Should the login form be displayed if neccessary?
     * @return void
     */
    function Auth($storageDriver, $options = '', $loginFunction = '', $showLogin = true)
    {
        $this->applyAuthOptions($options);

        // Start the session suppress error if already started
        if(!session_id()){
            @session_start();
            if(!session_id()) {
                // Throw error
                include_once 'PEAR.php';
                PEAR::throwError('Session could not be started by Auth, '
                        .'possibly headers are already sent, try putting '
                        .'ob_start in the beginning of your script');
            }
        }





2. When using a container (e.g. MDB2) the documentation suggests a return value, but the code doesn't return anything.

Code:

    /**
     * Constructor of the container class
     *
     * Initate connection to the database via PEAR::MDB2
     *
     * @param  string Connection data or MDB2 object
     * @return object Returns an error object if something went wrong
     */
    function Auth_Container_MDB2($dsn)
    {
        $this->_setDefaults();

        if (is_array($dsn)) {
            $this->_parseOptions($dsn);
            if (empty($this->options['dsn'])) {
                PEAR::raiseError('No connection parameters specified!');
            }
        } else {
            $this->options['dsn'] = $dsn;
        }
    }



3. What's the easiest way to trap and then use a database connection error for example? The main errors seem to be checked for by the code, but not always returned by the methods. Would I need to set a callback with PEAR::setErrorHandling() to provide my own error handling?

4. Ideally I'd like to write the login/out events to a log file to check for hacking attempts, etc. What would be the best way to do this with PHP and/or PEAR?

Thanks for any suggestions or ideas you may have.

Max
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Thu May 17, 2007 6:32 pm    Post subject: Re: Auth 1.5.1 , error handling etc Reply with quote

Only a general comment (as I don't have any experience with Auth):

MaxT wrote:
When using the constructor, something like;

$auth = new Auth(...);

Do you need to wrap in a try / catch block?

Looking at the code in Auth.php there is a possible Exception (throwError), but this is not documented.


Auth is a PHP 4 package and does not throw exceptions. throwError() "throws" a PEAR_Error object. It isn't returned here (and in your second code snippet), because the lines are located in the constructor.
Back to top
View user's profile Send private message
MaxT



Joined: 17 May 2007
Posts: 4

PostPosted: Fri May 18, 2007 10:33 am    Post subject: Error handling Reply with quote

Thanks Mark, the error handling makes a bit more sense now. To check for these errors and do something about them I would have to use PEAR::setErrorHandling() or something similar to get access to the error information.

Max
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Authentication All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software