doulian8554 2014-05-01 15:49
浏览 103

为登录用户创建匿名模式的最佳方法?

I'm working on a Web App similar to a discussion board and I want to give logged in users the ability to switch to an anonymous mode in which their username is not displayed but replaced by an ID when they post or reply to a topic. So the question is what is the best way to generate this ID given that :

  • A user has the same ID in the same topic.
  • The ID for the same user is different from a topic to another.

I'm in a LAMP environment so if you can suggest any PHP function to generate the ID or a way to store it in MySQL database that will be great.

Thanks !

  • 写回答

1条回答 默认 最新

  • duanmei2805 2014-05-01 16:08
    关注

    All you really need is to:

    • be able to create an id, which in your case should probably be globally unique
    • associate that id with your regular user's id
    • be able to track that a unique id belongs to a topic

    You can do this easily with one extra table:

    table anonymous_ids
    -------------------
    user_id      INT    (references your user id)
    anonymous_id VARCHAR, UNIQUE index
    topic_id     INT    (references your threads/topic id)
    

    When a user replies in a topic, you check whether there's already an anonymous id for him in this topic:

    SELECT anonymous_id
      FROM anonymous_ids
     WHERE user_id  = {userId}
       AND topic_id = {topicId}
    

    If there is no such id yet, you create it. That's the basic gist of it.

    评论

报告相同问题?

悬赏问题

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