Comdemned Posted January 7, 2008 Share Posted January 7, 2008 Hi, Is there anyway to have a or in an if statment eg <?php if (!$_SESSION['perm'] = 1 or 2){ die("you shouldnt be here"); } ?> or do you have to so it like <?php if (!$_SESSION['perm'] = 1){ if (!$_SESSION['perm'] = 2){ die("you shouldnt be here"); } } ?> also when doing it this way is there any way to stop the if statment from setting $_SESSION['perm'] = 2 as it is and its messing with my authentication. Ive searched the forums lots but its kind of hard to search for "or" as it shows up so often. Thanks in advance Murray Quote Link to comment https://forums.phpfreaks.com/topic/84844-solved-or-in-an-if-statment/ Share on other sites More sharing options...
phpQuestioner Posted January 7, 2008 Share Posted January 7, 2008 <?php if ((!$_SESSION['perm'] == "1") || (!$_SESSION['perm'] == "2")) { die("you shouldnt be here"); } ?> http://www.php.net/manual/en/language.operators.logical.php Quote Link to comment https://forums.phpfreaks.com/topic/84844-solved-or-in-an-if-statment/#findComment-432535 Share on other sites More sharing options...
Comdemned Posted January 7, 2008 Author Share Posted January 7, 2008 Thank you that has solved both problems, I thought the || in an if statment ment AND not OR. Also i noticed you used == instead of =, which has fixed the problem of the if statment setting $_SESSION['perm'] =2, what exactly does == mean compared to = other that it will not update the variable? Murray PS sorry didnt see that link at the bottem. thanks again Murray Quote Link to comment https://forums.phpfreaks.com/topic/84844-solved-or-in-an-if-statment/#findComment-432537 Share on other sites More sharing options...
Highlander Posted January 7, 2008 Share Posted January 7, 2008 the = sets the variable and == compares the left and the right side: $id = 3; // Sets $id to 3 if ($a == $b) { // Checks if $a has the same content as $b } Quote Link to comment https://forums.phpfreaks.com/topic/84844-solved-or-in-an-if-statment/#findComment-432538 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.