谁能看到与以下问题相关的速记法有什么问题吗?

echo "<td><font size=1 color=#e4d6b5>" . ($row['tier']<$_SESSIONS['tier'] ? "ACCESS DENIED" : $row['contents']) . "</font></td>";


我的数据库中有两个表:

1.)成员(id,用户名,电子邮件,密码,盐,层)
2.)opwire(类别,内容,日期,用户标识,安全级别)
我试图根据其安全级别(引用成员级别与opwire的seclevel)来授予当前登录用户“内容”的访问权限或受限访问这些内容的权限。我也不完全确定自己正在使用http:// www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL

通常,我可以通过以下方式获得当前用户:

$userId = $_SESSION['user_id'];


整个表构建php在下面。当前,具有任何层的用户在应限制其级别时,可能会错误地查看任何seclevel内容。

<?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 "Case 1":
       return "#cbae80";

       case "Case 2":
       return "#e59350";

       case "Case 3":
       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['tier']<$_SESSIONS['tier'] ? "ACCESS DENIED" : $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/>';
}

?>

最佳答案

我相信在每种情况下您都需要在结尾处加上“ BREAK”,否则它将一直贯穿到“#b7aaa4”;

function getColor($strOption)
 {
  switch ($strOption)
  {
   case "Case 1":
   return "#cbae80";
   break;

   case "Case 2":
   return "#e59350";
   break;

   case "Case 3":
   return "#b7aaa4";
   break;
  }
}

08-06 01:57