简体   繁体   中英

Block User From Profile

I am wanting to create a user block I have the button

<a type="button" value="1" name="block" Cursor="pointer" href="blockuser.php?uid='. $data['id'].'">Block</a>

But I'm wanting to know how best to do this with PHP, Ajax and either the users table or a separate blockuser table. So when I click on block I cansend the value 1 to the database with the users id and stop them from veiwing my whole profile with a switch and visa versa.

I will then go on to creating a block list with the ability to unblock this user at any given point, if users so wish.

Privacy is a must! Thanks for any help given.

The only real question in your question is whether to create a new table for this or not, as the rest is a group of very straight-forward tasks for the technologies you mentioned.

Personally, I would opt for simply adding a column to the current users table and filling it with a comma delimited list of User IDs which you could simply search for a user ID within. This has the advantage that you'll only need to run one query vs. the two which would be required to check the block list and then get the viewed user's info in the two-table scheme.

Adding users to the blocklist is trivial (append a user id and perhaps a comma), and dropping the user from the blocklist would simply require splitting the blocklist, removing the proper user ID, then rebuilding the list by joining with a comma.

Also, this is only useful to implement if you require authentication to view a profile, and even then one could circumvent such a system by simply creating a new account.

On each row in the database where you store the profile information (perhaps the members table?) you can add a row called "blocked" which stores the ID numbers of the members that are blocked. I would separate these numbers using semi-colons personally and $blocked_ids = explode(";",$blocked) to get each blocked ID. From there you can check if the person is to be blocked from the profile by using: if(in_array($user_id,$blocked_ids)) , if that value is in the array, prevent the profile view.

Hope this helps you, any questions just comment below

As far as the database goes, I would probably do it like this - create a table specific for blocks. Two essential fields would be the id of the blocker and the id of the person being blocked. This means that if one person blocks two users, he'll have two entries in the table - don't try creating one SQL field to act like an array.

Currently, you're setting up to use a standard request to a PHP stage with a $_GET parameter. There's nothing majorly wrong with that, but if you want the whole operation to happen without your page refreshing, you can use Ajax. With jQuery: $.get("remove.php", { uid: "someID" } );

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