dongle7637 2016-03-14 14:49
浏览 37

显示特定用户的图像

I have a website coded in html/css and a bit of js and jQuery.

MySql is my choice of database.

I have a login-system and users can create their own accounts on my site.

The problem is, that I'm trying to somehow restrict users so that only user A can view content (in this case, images) that I have specified for him. User B can only view its own content and so on.

I tried to mess with Role Based Access Control in php but I failed.

I'm looking for a simple solution. I have one (1) table with users where the "user_id" is the primary key.

Isn't there a way to do something like this?

if(user_id == 1) {
Do somethnig here
}
  • 写回答

1条回答 默认 最新

  • dongxuying7583 2016-03-14 15:00
    关注

    Charles, as commented there are many "open source content management systems" available that do this out of the box - I personally favour http://www.silverstripe.org/

    However your question is about how to structure your database and I would recommend a "many many" relationship ( https://en.wikipedia.org/wiki/Many-to-many_(data_model) ). To create this you will need a table in the middle that stores all the id's from both ends.. e.g.

    member - id - plus other fields
    
    member_image - contains only member_id and image_id
    
    image - id - plus other fields
    

    to complete your code example...

    $sql = "SELECT 1 FROM member_image WHERE member_id = $iMemberID AND image_id = $iImageID"
    

    ...it would be "if" the above SQL returned a row or not they member can access that image

    评论

报告相同问题?