Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

privacy concerns- database

if i have this table:

users
-----
id_users (pk)
age
name
gender
salary

it is needed for each of these values an option to set visible or not in user profile. What do you think that is the best way to do that?

For example hide the field salary to the person x, but allows to the person y. basically some persons can watch some attributes.

thanks

like image 522
anvd Avatar asked Sep 22 '26 09:09

anvd


1 Answers

If the default privacy will be show to all, then you can create a table to hold all the hide settings of a certain user to a certain user.

This is the table I would suggest, with a compound PK of the three columns:

hide_details
------------
visitor_id
user_id
what

Some sample data would be:

visitor_id      |       user_id     |       what
    1                       2               age
    1                       2               name
    3                       4               salary

This table schema will not have to be updated in the future if you add another column to your users' table. Suggestion, if you want to make this amazingly fast you can map the column names to integers, and use that in your application logic to compare against. E.g. name = 1, age = 2, etc... So, when you do the comparison to hide the name or not, you just check if there is a record with that integer in the hide array.

You can use it like the following: before you display a profile, you fetch all the hide records of that visitor to that profile, and put them in an array, and then display anything, which hasn't been hidden.

E.g.

$hide = array('name', 'age', 'salary');

Then, you can check like:

echo (in_array($hide)) ? '' : '<div>Name:'.$name.'</div>';
like image 175
Shef Avatar answered Sep 24 '26 01:09

Shef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!