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? Quote Link to comment Share on other sites More sharing options...
Orio Posted March 25, 2007 Share Posted March 25, 2007 Change the or to and. Orio. Quote Link to comment Share on other sites More sharing options...
psychohagis Posted March 25, 2007 Author Share Posted March 25, 2007 Why would that work? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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>'); } ?> 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.