I have a very simple PHP function to check log-in
function check_login($user, $pass) {
if(!isset($user) || $user == '') {
return 'Please enter a valid username';
}
else if(!isset($pass) || $pass == '') {
return 'Please enter a valid password';
}
else {
return 'true';
}
}
How can I return an error message and false same time and return true instead of 'true' as a string. Like,
function check_login($user, $pass) {
if(!isset($user) || $user == '') {
return 'Please enter a valid username' //return false;
}
else if(!isset($pass) || $pass == '') {
return 'Please enter a valid password' //return false;
}
else {
return true;
}
}
So I can check like if(check_login($uname, $pword)){
instead of checking like if(check_login($uname, $pword)=='true'){
:)
Why not just check if it's true
, and handle from there.
$login = check_login('user', 'pass');
if($login === true)
loginUser(); //login was successful, finalize or whatever
else
echo $login; //error message
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With