jattsurma Posted February 16, 2011 Share Posted February 16, 2011 Hello Everyone, From time to time, I get into a situation where my if statements do not give the desired results. I always have to play around with them to get the things working. I'm in same situation right now. I'm guessing that I do not completely understand the logic. If someone can take a look at the code below and tell me what's wrong, it will be greatly appreciated. if($_SESSION['account_type'] != 'internal admin'){ die('<font color="red"><b>Error:</b> This page can only be accessed by internal or super admin.</font>'); break; } elseif($_SESSION['account_type'] != 'super admin'){ die('<font color="red"><b>Error:</b> This page can only be accessed by internal or super admin.</font>'); break; } I have echoed out the $_SESSION['account_type'] and I'm getting "internal admin" but for some reason, I'm getting the error "Error: This page can only be accessed by internal or super admin." Thanks in advance for your help. Jatt Surma Quote Link to comment Share on other sites More sharing options...
ansharma Posted February 16, 2011 Share Posted February 16, 2011 if($_SESSION['account_type'] != 'internal admin'){ die('<font color="red"><b>Error:</b> This page can only be accessed by internal admin.</font>'); break; } elseif($_SESSION['account_type'] != 'super admin'){ die('<font color="red"><b>Error:</b> This page can only be accessed by super admin.</font>'); break; } try this , coz you are displaying the same message for both condition Quote Link to comment Share on other sites More sharing options...
jattsurma Posted February 16, 2011 Author Share Posted February 16, 2011 hello ansharma, Thanks for your help. I understand why I'm getting that message. It's because I'm logged in as "internal admin" and than I have same statement saying that "If account type is not super admin" show that error. What I'm trying to do is that only the "Super admins" and "internal admins" have access to that page. So customers or anyone else can not view it. How should I do that? Thanks again for your time. Jatt Surma Quote Link to comment Share on other sites More sharing options...
EmlynK Posted February 16, 2011 Share Posted February 16, 2011 You could try this: $accountTypes = array("internal admin","super admin"); if(!in_array($_SESSION['account_type'], $accountTypes)) { die('<font color="red"><b>Error:</b> This page can only be accessed by internal or super admin.</font>'); break; } That should effectively do the same thing. Let us know if it works, please? Quote Link to comment Share on other sites More sharing options...
jattsurma Posted February 16, 2011 Author Share Posted February 16, 2011 Hello EmlynK, You are a GENIUS. it worked like a charm. Thank you! Jatt Surma Quote Link to comment Share on other sites More sharing options...
EmlynK Posted February 16, 2011 Share Posted February 16, 2011 You're very welcome. I'm glad it worked. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.