简体   繁体   English

编辑已登录用户的会话数据

[英]Editing session data of a user who is logged in

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 用户norman登录,并设置了以下会话cookie $ _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? 我需要将该Cookie设置为1。我可以更改Cookie的值吗? 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? 如何才能做到这一点?

Do not edit the session variable. 不要编辑会话变量。 There's much better approach for this purpose. 为此目的,有更好的方法。

Use one more column in users table named post_access . users表中再使用一列名为post_access If you allow Norman to post, its value would be 1, while blocked user will get 0. 如果允许Norman发布,则其值为1,而被阻止的用户将获得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. 假设您已阻止用户发布信息,因此您已将users表中post_access列的值更改为0。

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. 现在,在您创建帖子的脚本中,在发布数据之前,通过使用author会话名称与表'users'中新查询的用户数据进行比较,确定是否将用户的帖子访问权限设置为1。

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. 这将是控制职位的最有效方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM