psychohagis Posted March 25, 2007 Share Posted March 25, 2007 I have the following if statement: if ($_SESSION['rank']!='webmaster' OR $_SESSION['rank']!='chairman' OR $_SESSION['rank']!='secretary' OR $_SESSION['rank']!='treasurer') { exit('<meta http-equiv=refresh content=0;URL=http://www.MYSITE.org.uk/events.php>'); } I dumped the variable $_SESSION['rank'] and it came out as "webmaster" but I still get redirected away? Can anyone help? Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/ Share on other sites More sharing options...
Orio Posted March 25, 2007 Share Posted March 25, 2007 Change the or to and. Orio. Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214891 Share on other sites More sharing options...
psychohagis Posted March 25, 2007 Author Share Posted March 25, 2007 Why would that work? Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214894 Share on other sites More sharing options...
papaface Posted March 25, 2007 Share Posted March 25, 2007 It wouldnt. Do you have session_start(); at the top of the page? Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214895 Share on other sites More sharing options...
psychohagis Posted March 25, 2007 Author Share Posted March 25, 2007 Well i tried that and it works but i dont understand why. Surely AND would require all of them to evaluate to true where as OR only needs one of them to evaluate to true - which makes more sense to me because $_SESSION['rank'] can't have multiple values. Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214896 Share on other sites More sharing options...
papaface Posted March 25, 2007 Share Posted March 25, 2007 You are correct. Maybe Orio can shed some light. Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214897 Share on other sites More sharing options...
designationlocutus Posted March 25, 2007 Share Posted March 25, 2007 Might be good to go with the switch statement on this one Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214904 Share on other sites More sharing options...
Orio Posted March 25, 2007 Share Posted March 25, 2007 events.php is for authorized users, or unauthorized? If it's for authorized, then you need to keep the OR, but it seemed to me it's for unauthorized users. Now, for the session_start() part, you need to use that because if you don't use it the $_SESSION array is not restored. Every time you want to use the $_SESSION array, make sure you call session_start(). Orio. Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214908 Share on other sites More sharing options...
psychohagis Posted March 25, 2007 Author Share Posted March 25, 2007 yh ive got session_start() on every page. events.php is for both authorised and unauthorised users depending on what part of it youre in. I just dont see the logic behind using AND when i only need one of the statements to evaluate to true Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214914 Share on other sites More sharing options...
designationlocutus Posted March 25, 2007 Share Posted March 25, 2007 If you use the switch statement, you could do something like: <?php session_start(); $rank = $_SESSION['rank']; switch ($rank) { case "webmaster": case "chairman": case "secretary": case "treasurer": // Do whatever break; default: exit('<meta http-equiv=refresh content=0;URL=http://www.MYSITE.org.uk/events.php>'); } ?> Link to comment https://forums.phpfreaks.com/topic/44248-problem-with-if-statement/#findComment-214924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.