1

我的数据库中有两个表: 1.) members (id,username,email,password,salt,tier) <-tier 是用户的安全许可级别。2.) opwire (category,contents,date,userid,seclevel) <-opwire 存储用户提交的数据,userid 是一个数字,引用刚刚向 opwire 提交数据的用户。Seclevel 是用户查看特定提交数据所需的安全许可级别。

然后我有一个名为 get_opwire.php 的 php 文件(如下所示),它从 opwire 中提取信息并将其列在表中。我想要完成的是通过引用 tier vs seclevel 来限制/允许信息。

例如,假设 opwire 看起来像这样:

-类别/内容/日期/用户ID/秒级别

- 敌人位置/法院后面的坦克/今天/1/5

-物品位置/垃圾桶里的火箭筒/今天/1/2

如果 Bob 已登录并且他具有第 3 层访问权限,他将看到

-敌人位置/拒绝访问/今天/管理员

-物品位置/垃圾箱中的火箭筒/今天/管理员

(Admin 只是提交数据的用户,即 userid。)所以实际上只有内容区域 echo 需要反映这种变化。我考虑过使用 >= 原则的嵌套 if/while(如果 Bob 的层号 >= seclevel,则回显内容,否则回显访问被拒绝),但老实说,修改我在这里所做的明智的语法有点超出了我的头。

有人能帮忙吗?这是get_opwire.php:

<?php 

include_once 'functions.php';
include_once 'db_connect.php';
sec_session_start();

if(login_check($mysqli) == true) {

$con=mysqli_connect("localhost","mylogin","mypassword","mysqldatabase");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


function getColor($strOption)
{
   switch ($strOption)
   {
       case "Enemy Location":
       return "#cbae80";

       case "Item Location":
       return "#e59350";

       case "Another Category etc":
       return "#b7aaa4";

    }
}


$result = mysqli_query($con,"SELECT opwire.*,members.username FROM opwire 
          LEFT JOIN members on opwire.userid=members.id order by date DESC");

echo "<table border='1'>
<tr>
<th>Category</th>
<th>Contents</th>
<th>Date/Time</th>
<th>Operative</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><font size=1 color='".getColor($row['category'])."'> " . $row['category'] . "</font></td>";
  echo "<td><font size=1 color=#e4d6b5>" . $row['contents'] . "</font></td>";
  echo "<td><font size=1 color=silver>" . $row['date'] . "</font></td>";
  echo "<td><font size=1 color=gold>" . $row['username'] . "</font></td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);

} else {
   echo 'Access to this area requires security clearance. <br/>';
}

?> 
4

0 回答 0