For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > June 2004 > Re: [PEAR] Auth? Can I generate customized error messages based on the type of login









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] Auth? Can I generate customized error messages based on the type of login
Paul M Jones

2004-06-24, 3:55 pm


On Jun 24, 2004, at 8:36 AM, bclem@imaginative-enterprises.com wrote:

> Hi All,
>
> Is it at all possible to return the exact type of login failure from
> the auth
> class rather than just the constant value of -3? If so, how would I do
> it?


Not exactly, but you can use the return value to generate a message.
Set up an array like this ...

$errorMessages = array(
AUTH_IDLED => 'idle for too long, log in again',
AUTH_EXPIRED => 'session expired, log in again',
AUTH_WRONG_LOGIN => 'wrong username/password combination, try again'
)

.... and then check Auth::getStatus(); if you get a negative value, use
it with that array to pick the appropriate message. You will need to
convert the getStatus() value to a string when you do so, because PHP
won't use negative integer values for array keys. E.g.:

// $a is an Auth object
$errcode = $a->getStatus();
if ($errcode < 0) {
echo $errorMessages[ (string) $errcode ];
}

Hope this helps.


--

Paul M. Jones

Savant: the simple alternative to Smarty for PHP.
http://phpsavant.com/

DB_Table: build RDBMS tables and XHTML forms in one PHP class.
http://wiki.ciaweb.net/yawiki/index.php?area=DB_Table

Yawiki: your collaborative online documentation system.
http://yawiki.com/

Yawp: a single-file foundation for PHP applications.
http://phpyawp.com/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com