tryingtolearn Posted October 29, 2012 Share Posted October 29, 2012 Looking for an explanation I have three different user levels and I want to grant page access depending on the level. Say the levels are: Level A Level B Level C On this page I only want Levels A and B to access it I have it working by checking the Session value like this if ($_SESSION['user_level'] != 'A'){ if ($_SESSION['user_level'] != 'B'){ //redirect to the restricted page notice } } But it wouldnt work by doing any variation on one line in the if statement?? i.e. if (!isset($_SESSION['user_level']) || ($_SESSION['user_level'] != 'A')|| ($_SESSION['user_level'] != 'B')) { //redirect to the restricted page notice } it simply redirects everyone. Is there a way to get it on lne line vs. nesting the if statements - just out of curiosity.. THanks Quote Link to comment https://forums.phpfreaks.com/topic/270025-comparing-sessions-using/ Share on other sites More sharing options...
OOP Posted October 29, 2012 Share Posted October 29, 2012 (edited) Hi there, you can simply change your statement to the below: if (!isset($_SESSION['user_level']) || ( ($_SESSION['user_level'] != 'A') AND ($_SESSION['user_level'] != 'B')) ) { //redirect to the restricted page notice } That should work Edited October 29, 2012 by OOP Quote Link to comment https://forums.phpfreaks.com/topic/270025-comparing-sessions-using/#findComment-1388392 Share on other sites More sharing options...
tryingtolearn Posted October 29, 2012 Author Share Posted October 29, 2012 Worked perfect, thanks alot for ttat When I read it, it seems liike its saying that the A and B have to be true to redirect, I guess thats why I wasnt figuring it out. Thanks for taking the time. Quote Link to comment https://forums.phpfreaks.com/topic/270025-comparing-sessions-using/#findComment-1388394 Share on other sites More sharing options...
OOP Posted October 29, 2012 Share Posted October 29, 2012 You are most welcome my friend, any time Quote Link to comment https://forums.phpfreaks.com/topic/270025-comparing-sessions-using/#findComment-1388395 Share on other sites More sharing options...
Christian F. Posted October 29, 2012 Share Posted October 29, 2012 What is says is that is has to be different (not equal) to both A and B, before it will redirect. It can be a bit confusing at first, but once you wrap your head around it the NAND pattern can be quite useful. Quote Link to comment https://forums.phpfreaks.com/topic/270025-comparing-sessions-using/#findComment-1388419 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.