尝试使用三个值来创建一个 if 语句,但似乎每次都得到错误的结果
Trying to use three values to create an if-statement, but seem to get the wrong results every time
$creator_id = $post[0]->users->user_id;
$edit_id = $this->_user->user_id;
$rank_id = $this->_user->rank_id; //3 or higher is mod+admin
if($edit_id != $creator_id) {
die("You didn't make this post");
}
if($rank_id >= 3) {
die("You are a moderator or higher");
}
// statement that checks whether you made the post, if you did
// not make the post, but you are a moderator or higher, you
// are allowed to enter the page
我正在使用三个值,$creator_id、$edit_id 和 $rank_id 进行 if 语句。我想要实现的是上面显示的代码的注释。
我尝试了很多不同的东西,但似乎总是失败。我的目标是检查 edit_id(尝试编辑 post 的用户)是否匹配 creator_id(创建 post 的用户),如果不匹配,我们不应该允许用户访问,in that case die("You didn't make this post");.
但是,我想在同一个语句中添加一些内容来检查您是否是版主或更高级别 (x >= 3)。如果您没有post,但是,您是版主或更高级别,您应该可以访问post。
如果 ID 不同,则永远不会到达第二个 if
语句。
您可以使用单个 if
语句。
if ( $edit_id !== $creator_id && $rank_id < 3 ) {
die('You do not have the rights to visit this post');
}
$creator_id = $post[0]->users->user_id;
$edit_id = $this->_user->user_id;
$rank_id = $this->_user->rank_id; //3 or higher is mod+admin
if($edit_id != $creator_id) {
die("You didn't make this post");
}
if($rank_id >= 3) {
die("You are a moderator or higher");
}
// statement that checks whether you made the post, if you did
// not make the post, but you are a moderator or higher, you
// are allowed to enter the page
我正在使用三个值,$creator_id、$edit_id 和 $rank_id 进行 if 语句。我想要实现的是上面显示的代码的注释。
我尝试了很多不同的东西,但似乎总是失败。我的目标是检查 edit_id(尝试编辑 post 的用户)是否匹配 creator_id(创建 post 的用户),如果不匹配,我们不应该允许用户访问,in that case die("You didn't make this post");.
但是,我想在同一个语句中添加一些内容来检查您是否是版主或更高级别 (x >= 3)。如果您没有post,但是,您是版主或更高级别,您应该可以访问post。
如果 ID 不同,则永远不会到达第二个 if
语句。
您可以使用单个 if
语句。
if ( $edit_id !== $creator_id && $rank_id < 3 ) {
die('You do not have the rights to visit this post');
}