duannei1477 2012-03-30 20:49
浏览 47
已采纳

PHP - 如何从数据库中将字符串信息解析为可用的形式

I am working on a web-app system that has multiple apps, each with a Primary Key to identify them. Each user also has a security level tied to an app, for instance App #1 with a security level of 5. I want to store all the app / security information in the database as a token, and then retrieve that information to store it in Session.

So given the following apps:

  1. Task App
  2. Email App
  3. Notes App

and a user that has security level 3, 5, and 7 respectively, the token will be stored as:

1.3|2.5|3.7.

My question is, how do I retrieve that data in a usable form? I was thinking of having it in an array, with the array key of the App ID, like somearray[1] = 3, somearray[2] = 5, etc, but I have no idea how to handle this.

I'm early in development on this part, so I have a very open mind towards suggestions. Thanks in advance for the help.

  • 写回答

4条回答 默认 最新

  • duanqinbi9029 2012-03-30 20:54
    关注

    the token will be stored as:

    1.3|2.5|3.7.

    Why don't you store security levels in a database ? It will be much more easy to manage. I could imagine few tables like the following:

    App
    --------
    id
    name
    ....
    
    Users
    --------
    id
    name
    email
    ...
    
    App_users_permissions
    --------
    id
    app_id (references App.id)
    user_id (references Users.id)
    level
    

    Then, you could do a simple query like:

    SELECT level FROM App_users_permissions WHERE user_id = 1 AND app_id = 2
    

    This query would then return the current previlege id, for a given app id and user id.

    I think that would be the easiest way to manage this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'