duanraa1984 2013-05-03 16:14
浏览 11

编辑登录用户的会话数据

Is it possible to edit the session data of a user who has logged in?

Eg. User norman logs in, and the following session cookie is set $_SESSION['addPost']=0

This means a user can add posts. Lets say I want to block that user from adding posts. I need to set that cookie to 1. Can i change the cookie value? Because, untill a user logs out and logs in again, it will not change, and he'll still be able to add posts.

How can this be done?

  • 写回答

1条回答 默认 最新

  • dongqiang8683 2016-07-07 08:18
    关注

    Do not edit the session variable. There's much better approach for this purpose.

    Use one more column in users table named post_access. If you allow Norman to post, its value would be 1, while blocked user will get 0.

    Let's say you have blocked a user from posting, so you have changed the value in post_access column to 0 in users table.

    Now in the script of your post creation, before posting the data, make a condition if user's post access is set to 1 or not by comparing with the new queried user data from table 'users' using session name of author.

    Sample:

      $userdata = get( 1 from "users" where user = "$_SESSION['user']"); //don't mind the get function. Use your own QUERIES. Just mind the logic. 
      $post_access = $userdata['post_access']; 
      if($post_acess == 1){
         //post the data
      }else{
         //Bro you are blocked
      }
    

    This would be most effective way to control posts.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。