douse8732 2011-09-20 09:12
浏览 24
已采纳

具有不同用户级别的php mysql登录系统[关闭]

I already have an existing login system using php and mysql using sessions. I think i do not need to post the code here.

i want to add a user level feature to it, wherein it limits the pages that can be viewed by a registered user depending on his access level. Example user level 1 can can access pages 1-5 only, and user level 2 can access pages 1-10, and so on.

i addedd a userlevel column on my members table. and i do not know what is the next step.

what particular function / code can be used to set the user level restrictions on the pages?

i tried searching out for examples in the web but can't find any good one.

please help

  • 写回答

4条回答 默认 最新

  • duane9322 2011-09-20 09:24
    关注

    You haven't given me much information as to what's happening (Maybe that's why your username is PHPNewbie).

    What I did have done with a previous user system of mine is I had a separate table called groups. In the groups table it had boolean values of different privileges in columns (such as canComment). Whenever I needed to verify if a user could perform an action, I just checked for a true value in action's column.

    You could implement this by having a broader user system, where an integer userLevel could indicate the group of the user (0 - root, 1 - basic etc.). What it appears you want is a page restriction system. I can suggest you use a switch statement that retrieves the userLevel as so -

    switch(userLevel) { //Where userLevel is an int retrieved from the session/database
    case 0:
        echo $page;
    break;
    
    case 1:
        echo "You cannot access this resource...";
    break;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程