开发者

Help with PHP IF statement - OR AND etc

I have a little problem. I wish to create an IF statement, that shall react like this:

  • If user is NOT admin (forum_admin) AND they are not the owner of the ticket (userid), BUT moderators are allowed to view tickets (allow_moderator_tickets) AND user is moderator (forum_moderator), then he should be allowed to view the ticket.

How can I obtain this with a PHP if statement.

So far I have this:

 //If user is not allowed to view.  
    if($userdata['forum_admin']==0 && $ticketDetails['userid']!=$userdata['id'] || $sdata['allow_moderator_ticket']==0 && $userdata['forum_moderator']==1)
    开发者_JAVA百科    redirect("?i=a");


 if ( isAdmin || (allowModerators && isModerator) || userID == ticketUser ) allowToSeeTicket

 if ( ! (isAdmin || (allowModerators && isModerator) || userID == ticketUser) ) notAllowToSeeTicket


you cannot mix and and or operators. each other will spoil another. you should group your expressions, using parenthesis, much like in arithmetics

it would be nice to refactor your code to make it readable

$admin = ($userdata['forum_admin']);
$owner = ($ticketDetails['userid'] == $userdata['id']);
$moder = ($sdata['allow_moderator_ticket'] == 1 AND $userdata['forum_moderator']==1)

if !($admin OR $moder OR $owner) {
    redirect("?i=a");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜