@dresden_phoenix ;
The point I was trying to make was testing on the off-chance for variable validity slows the login process.
Maybe better to assume valid login details and return false with a message.
PHP Code:
# set variables
$uname = 'valid-name'; #array(1,2,23); # 'valid-name';
$pword = 123456789 ;
$error = '';
# pass variables and define result
define('LOGGED_IN', login($uname, $pword, $error) );
# show results
echo LOGGED_IN ? 'LOGGED_IN' : 'FAILED BECAUSE ' .$error;
echo '<br />$uname: ', $uname;
echo '<br />$pword: ', $pword;
echo '<br />$error: ', $error;
//===============================================
//
// useage - login($uname, $pword, & $msg_by_ref);
//
// return - true or false with and 'error message'
//
//===============================================
function login($uname, $pword, & $msg_by_ref = 'dummy and not used')
{
$result = ($uname === 'valid-name') && (123456789 === $pword);
try
{
if ( ! $result)
{
#$err = 'FAILED THE FOLLOWING TESTS';
if (is_array($uname)) $err = 'Its an array()';
else if (is_string($uname)) $err = 'String does not match';
else if (is_bool($uname)) $err = 'Its a boolean';
else if(is_numeric($uname))
{
if ($uname > 0) $err = 'Its more than Zero';
else if ($uname < 0) $err = 'Its less than Zero';
else $err = 'Its ZERO';
}
else if (empty($uname)) $err = 'Its empty()';
else
$err = 'FAILED THE FOLLOWING TESTS';
throw new Exception($err);
}
}
catch( Exception $e )
{
$result = false; # heading($e->getMessage());
$msg_by_ref = $e->getMessage();
}
return $result;
}
Bookmarks