doutou7549 2012-05-09 01:45
浏览 42
已采纳

基于登录状态PHP的条件显示链接

I have a small site which has 200 members. Below is code for the login/logout links which display a "Change Password", "Report" and "Logout" link when logged in. While not logged in, the "Login" and "Forgot password" links are displayed.

Recently we ran a competition which had 14 winners and what I am trying to achieve is to put a link into the code that only the 14 winners can see and not the remaining members.

I'm not quite sure where to start, is it possible to put a condition in this code for the 14 user ids/email addresses or would I be better off putting a new field into the user's database? Any help or push in the right direction would be appreciated!

     <?php # loginnav.php> 

     // Display links based upon the login status. 

     // Show LOGIN links if this is the LOGOUT page. 

      if (isset($_SESSION['user_id']) 
      AND (substr($_SERVER['PHP_SELF'], -10) 
      !='logout.php')) 

      { echo 
      '<li><a href="logout.php">Logout</a></li>
       <li><a href="change_password.php">Change Password</a></li> 
       <li><a href="report.php">Report</a></li>  
     '; } else { 

     // Not logged in.   
     echo 
     ' <li><a href="login.php">Login</a></li> 
     <li><a href="forgot_password.php">Forgot Password?</a></li> 
      '; } ?>
  • 写回答

3条回答 默认 最新

  • duanfei1987 2012-05-09 02:02
    关注
         $winners_array = array('userid1', 'userid2', 'userid3', 'userid4', ...);  
              // This array contains users IDs who are winners
              // You can write it manualy right intj the login file, 
              //include it from external file or form from your Data Base
    
        if (isset($_SESSION['user_id']) 
          AND (substr($_SERVER['PHP_SELF'], -10) 
          !='logout.php')) 
          { 
          echo 
          '<li><a href="logout.php">Logout</a></li>
           <li><a href="change_password.php">Change Password</a></li> 
           <li><a href="report.php">Report</a></li>  
          '; 
          if(in_array($_SESSION['user_id'], $winners_array)){
             // If current ID is in winners list we add special link for him
             echo '<li><a href="winer_page.php">Winner link</a></li>';
          }
          } else { 
         // Not logged in.   
         echo 
         ' <li><a href="login.php">Login</a></li> 
         <li><a href="forgot_password.php">Forgot Password?</a></li> 
          '; } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 mysql全文索引查找指定必须关键词word无效
  • ¥20 关于CMOS电路图的提问
  • ¥15 Verilog hdl密码锁设计
  • ¥35 基于python的有ssl加密传输的socket聊天室
  • ¥15 数码管亮度控制器设计
  • ¥15 kafka客户端跨网段访问,看日志提示连接的还剩内网地址,且访问不通
  • ¥15 关于c语言代码的问题
  • ¥15 c51单片机控制步进电机
  • ¥20 Visual studio无法检测到设备
  • ¥30 vue 页面窗口放大或者缩小元素会变化