简体   繁体   中英

Display Images for Specific Users

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
}

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.. eg

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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