tags:

views:

122

answers:

4
if($process->g_User() && $process->g_Pass()){
         if($process->LdapConn()){
             if($process->LdapBind()){

                    return 'google';

             }else{
       procLogin();
         }
     }

     }

If my condition fails, it must call the procLogin() function but its not calling... the ProcLogin has just an echo...

if($process->g_User() && $process->g_Pass() && $process->LdapConn() 
   && process->LdapBind()) {
    return 'google';

When using this... it does not even call the google...

But in my latter code, at least it was calling...

My Requirement is... if the username and password is wrong, then it should fail regardless the connection is established or not.

A: 

Are you sure $process->LdapBind() is returning false and not $process->LdapConn()?

If I copy your example replacing the functions with true or false, it works just as expected when only $process->LdapBind() being false.

Maybe you want:

if($process->g_User() && $process->g_Pass()){
         if($process->LdapConn()  &&  $process->LdapBind()){
                    return 'google';
             }else{
                     procLogin();
         }
     }

     }
Tim Sylvester
It does not work
A: 

it will only trigger if both if($process->LdapConn()) AND if($process->LdapBind()) are true, are they?

smoove666
+3  A: 

EDIT: My Requirement is... if the username and password is wrong, then it should fail regardless the connection is established or not.

So, I take it that g_User() and g_Pass() validate each the username and password. As to what is 'fail' I'm guessing it's procLogin(). If 'fail' is return 'google', put the bodies the other way around.

If my assumptions are correct (which, again I cannot be sure of due to a sucky problem spec), then this is what you want

if($process->g_User() && $process->g_Pass()){
     if($process->LdapConn() && $process->LdapBind()){
        return 'google';
     }
} else {
     procLogin();
}


Never forget to indent correctly, and try to make your questions as clear as possible. For example, what is the condition you refer to is not clear at all... Now we all have to guess.

For example, if you want procLogin() to be called whenever a condition fails, and want to avoid repeating code you can take advantage of shortcircuiting to get the same behavior:

if($process->g_User() && $process->g_Pass() && $process->LdapConn() 
   && process->LdapBind()) {
    return 'google';
} else {
    procLogin();
}

Or, is it that you want procLogin() to be called if LdapConn() fails? Then you've misplaced the brackets:

if($process->g_User() && $process->g_Pass()){
     if($process->LdapConn()){
         if($process->LdapBind()){
            return 'google';
         }
     } else {
         procLogin();
     }
}
Vinko Vrsalovic
Not working... i get error
I want them if login fails
What part of making your questions clear didn't you get? Tell us what error have you gotten where! Also take the time to edit your question to clarify it. What exactly do you want?
Vinko Vrsalovic
Check now, i have edited
It throws me this error... Parse error: syntax error, unexpected T_OBJECT_OPERATOR in C:\xampp\htdocs\userMana\process.php on line 611
That error is that your syntax is wrong, you have written the code wrongly, missing a } (at least in your edit of the question you are missing a closing bracket) or missing something else...
Vinko Vrsalovic
A: 

If you want procLogin() called if login fails:

if($process->g_User() && $process->g_Pass()){
 if($process->LdapConn()){
  if($process->LdapBind()){
   return 'google';
  }
 }


} else {
// Login has failed
procLogin();
 }
David Archer