Page 1 of 1
How to make Page visible only for friends
Posted: 26 Jul 2017, 12:28
by JanMolendijk
How can i create that this code is only visible for friends-list ?
Code: Select all
<?php
include('connection.php');
$id = (int) $_GET['id'];
$sql=mysqli_query($conn,"SELECT * FROM `user` WHERE id='" . $id . "' ");
$users=mysqli_fetch_assoc($sql);
?>
<?php echo $users['user_relationship'];?>
How to make Page visible only for friends
Posted: 26 Jul 2017, 15:46
by Admin
Hello
It depends of the structure and relationship of your tables.
Generally, you should make something like this:
Code: Select all
<?php
//get the ID of the owner-user of accessed page
$id_user_pg =2;
//get and store in Session an array with the IDs of the friends of current user ($id)
$id_friends =[1, 2, 8];
//if $id_user_pg is in $id_friends shows the page, else some message
if(in_array($id_user_pg, $id_friends)) echo 'page';
else echo 'Not allowed to see the content';
?>
How to make Page visible only for friends
Posted: 27 Jul 2017, 10:46
by JanMolendijk
Ok i tried some things with the code but did not work out.
I have two tables one table with profile information, and a friend system for this i have also a table...
member_access
Code: Select all
id context user_id friend_id friend_name
user
I want table user only be visible for the friend_id from member_access from eatch user_id
How to make Page visible only for friends
Posted: 27 Jul 2017, 16:16
by Admin
An important thing is to get the ID of the owner-user of the accessed page.
Then, you make a Select to check if that ID is friend with the user who accesses the page.
Code: Select all
//id of current user
$id =4;
//here you should get the ID of the owner-user of accessed page
$id_user_pg =2;
//check if current user ($id) is ftiend with $id_user_pg
$sql=mysqli_query($conn,"SELECT friend_id FROM member_access WHERE friend_id=$id_user_pg AND user_id=$id LIMIT 1");
$nr_rows = mysqli_num_rows($sql);
//if $id_user_pg is friend with $id shows the page, else some message
if($nr_rows >0) echo 'page';
else echo 'Not allowed to see the content';
How to make Page visible only for friends
Posted: 29 Jul 2017, 11:28
by JanMolendijk
This where realy helpfull thanks for your support