D
D
Denis Fedorov2018-02-12 01:20:13
PHP
Denis Fedorov, 2018-02-12 01:20:13

How to correctly distribute access rights to users to records in the database?

Hello, I'm a complete newbie and can't figure out the following point.
I am writing purely for myself, I am not particularly interested in using "ready-made solutions" yet, because I want to understand more deeply how the connection between the database, server and user works.
Let's say the user is logged in. Now I want the user to be able to add content to the database. Let's say I did it too. But the bottom line is that only this user should see this content and only the user (assume with id = 5) should have access to this content. How should data be stored in a database? For each user to make their own table with content and give access only to this table? Then the question is how to make some rows from this table available to other users? Throw off pliz any articles, lessons for beginners. How to properly organize databases so that it is safe?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima, 2018-02-12
Dolgoter @DDolgy

You make a session variable with the user's I'd and when you write the content to the table,
then pass this variable as well, and when you pull the content from the database, then so that conditions like take information from such a table with such information pass, but at the same time, so that the session id is equal to the session id field in the database

A
artemmityushov, 2018-02-12
@artemmityushov

Two ways:
1. Keep user_id in each table and filter by it.
2. Create a separate value for single increments for all directories, or use the UUID type, and keep a bunch of record ID and user ID in a separate table.
The first is simpler, the second is more scalable, it will allow you to distribute records, for example, give access to several users to see one record.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question