2

我正在创建多用户应用程序。使用 php codeigniter 创建我正在寻求最佳实践或最佳方法来防止用户更改/删除其他用户数据。

我有一些关系表。

  1. tbl_users(用户 ID、用户名、密码)
  2. tbl_stores (store_id, user_id, store_name, store_url)
  3. tbs_products (product_id, store_id, product_name)

每个用户都有自己的店铺,每个店铺可能有很多产品。

那么,防止用户删除其他用户数据的最佳方法是什么?

实际上,我已经在模型中创建了一些代码,但由于我是新手,我不确定,如果这是正确的方法,我的代码是这样的。

function remove_product($product_id)
{
    $this->db->from('products as p');
    $this->db->join('stores as s', 's.id = p.store_id');
    $this->db->where('p.id', $product_id);
    $this->db->where('s.user_id', $this->session->userdata('id'));

    if($this->db->count_all_results())
    {
        $this->db->where('id', $product_id);
        return $this->db->delete($this->table);
    }
}

请告知这种方法是否正确,或者是否有更好的方法来做到这一点。

问候

4

1 回答 1

1

在删除某些内容之前,请检查其所有者是否与会话用户相同。

于 2011-05-21T01:26:22.227 回答