Jump to content

problem with if statement


psychohagis

Recommended Posts

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

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.

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>');
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.