根据登录的用户凭据禁用按钮。

时间:2012-12-10 13:04:16

标签: php

我有一个可供多个用户访问的页面。每个人登录并且PHP页面查找用户并验证该人。这也可以提取有关用户等级的信息。如果等级为1a或1b,我想禁用附加的搜索按钮,其他人都可以。我有其他JavaScript禁用DIV但我不能让它在这里工作。

    <div id="footer" style="background-color:#3399cc;clear:both;text-align:center;"><font  color="#000099">DJR</font>
    <a href="change.php"class="buttons">Change password</a>
    <a href="out.php" class="buttons">Logout</a>
    <a href="search.php" class="buttons">Search</a>
    <a href="Calendar.php" class="buttons">Calendar</a>
    <a href="AL.php" class="buttons">Leave</a>
    </div>

这是我获取有关当前用户的信息的方式!

  $fgmembersite->userID();

如果这等于除1a和1b之外的任何东西,则启用它。再次感谢,在这个网站上总是很有帮助。

3 个答案:

答案 0 :(得分:2)

为什么要向用户显示已禁用的按钮?只需回应他们可以使用的那些。

<?php 
  if(($fgmembersite->userID() == '1a') || ($fgmembersite->userID() == '1b')){
    echo '
      //echo buttons allowed to 1a and 1b users (or nothing at all)
    ';
  }
    else{
      echo '
        //echo buttons not allowed to 1a and 1b users (or nothing at all)
      ';
    }
?>

答案 1 :(得分:0)

使用此

<?php
    <a href="search.php" class="buttons"<?php if( $fgmembersite->userID()<>'1a' or  $fgmembersite->userID()<>'1b'  ){
echo " disabled='disabled' ";
}?>>Search</a>
?>

答案 2 :(得分:0)

下面的伪代码可以帮到你

<a href="search.php" class="buttons" <?php if(//users grade is 1a or 1b) { ?> onClick="return false;" <?php } ?> >Search</a>