0

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?

4

1 回答 1

0

不要编辑会话变量。为此目的有更好的方法。

users在名为的表中再使用一列post_access。如果您允许诺曼发帖,则其值为 1,而被阻止的用户将获得 0。

假设您已阻止用户发帖,因此您已将表中post_access列中的值更改为 0 users

现在在您的帖子创建脚本中,在发布数据之前,通过使用作者的会话名称与表“用户”中新查询的用户数据进行比较,确定用户的帖子访问权限是否设置为 1。

样本:

  $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
  }

这将是控制帖子的最有效方法。

于 2016-07-07T08:18:15.263 回答