dongshenghe1833 2013-10-17 12:37
浏览 31

检查用户权限的权限

I add values to user_privilege column by implode consist of permission of user that is ( 7gz,agt_courses,newbill,new_Trainee)=> each of them in real to open (say :newbill page) or not upon user permission in user_privilege column in "login" table in database in other words I want to check the user login his permission if it has say newbill permission he can open newbill page if not he can't open this page .

login table in database like this:

**username       username2          user_privilege**

amal             amal         7gz,agt_courses,newbill

ahmed           ahmed         dataDisplay,previllige,newUsers



$username = $_POST['username'];
$username2 = $_POST['username2'];

if($username && $username2)
{
    $finduser = mysqli_query($link,"SELECT * FROM LOGIN 
    WHERE username='".$username."' AND username2='".$username2."' AND FIND_IN_SET('Customers', user_previllige)") or die("error");

    if(mysqli_num_rows($finduser) !=0)
        {

            while($row = mysqli_fetch_array($finduser))
                {$uname = $row['username'];
                $uname2 = $row['username2'];}
        }

        if($username == $uname && $username2 == $uname2 )
            {$_SESSION['sessionname'] =$uname;
            $_SESSION['sessionname2'] =$uname2;
            header ("location:../customers/cutomer.php");}
                else echo '<script>function
{alert(you have not permission to open this page)}</script>';

    }

any body assist me ?

  • 写回答

1条回答 默认 最新

  • dpymrcl269187540 2013-10-17 14:07
    关注
    function check($sPermission, $sColumnValue)
    {
        $aPerm = explode(',', $sColumnValue);
    
        return (!empty($aPerm) && in_array($sPermission, $aPerm));
    }
    

    I hope you know how to select data from db, so call will looks like this:

    check('newbill', '7gz,agt_courses,newbill');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大