2
我正在創建多用戶應用程序。使用PHP codeigniter創建而我正在尋求最佳實踐或防止用戶更改/刪除其他用戶數據的最佳方法。如何防止用戶更改/刪除其他用戶數據
我有一些關係表。
- tbl_users(USER_ID,USER_NAME,密碼)
- tbl_stores(STORE_ID,USER_ID,STORE_NAME,store_url)
- tbs_products(產品,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);
}
}
請告知這種方法是否正確,或者如果有更好的方法來做到這一點。
Regards
感謝您的答案,所以它仍然需要2個查詢? – sgsg 2011-05-21 10:09:45
從產品中刪除WHERE ... AND userid = SESSIONUSER – 2011-05-21 10:14:33