Jump to content

Privacy options problems


jdowen
Go to solution Solved by jdowen,

Recommended Posts

I'm currently in the middle of developing a privacy options features which will allow members of my site to toggle whether their information is visible to friends only or to the public.

I'm doing this with PHP. When the privacy_opt variable is set to "fri" though, which means friends should only be able to see the content, the content isn't hidden to the public.

 

I'm using the following PHP code.

<?php
$sqlo = "SELECT * FROM user_optionsc0nf WHERE id='$id' LIMIT 1";
$opt_query = mysqli_query($db_conx, $sqlo);
// ------- WHILE LOOP FOR GETTING THE MEMBER DATA ---------
while($row = mysqli_fetch_array($opt_query, MYSQLI_ASSOC)){ 
    $privacy_opt = $row["privacy_opt"];
}
if ($privacy_opt == "fri" && $id != "$logOptions_id" && $friendArray == "$logOptions_id"){
 
echo "Only this person's friend can see this information.";
} else {
echo $website, $youtube, $locationInfo;
}
?>

 

The $friendArray variable contains the users friends ID's in the form of 51, 100, 22, etc.

$logOptions_id holds the ID of the current logged in user.

Edited by jdowen
Link to comment
Share on other sites

where does $logOptions_id come from and is it an array? Because if $friendArray is an array you probably don't want to compare it to $logOptions_id.

I'm currently in the middle of developing a privacy options features which will allow members of my site to toggle whether their information is visible to friends only or to the public.

I'm doing this with PHP. When the privacy_opt variable is set to "fri" though, which means friends should only be able to see the content, the content isn't hidden to the public.

 

I'm using the following PHP code.

<?php
$sqlo = "SELECT * FROM user_optionsc0nf WHERE id='$id' LIMIT 1";
$opt_query = mysqli_query($db_conx, $sqlo);
// ------- WHILE LOOP FOR GETTING THE MEMBER DATA ---------
while($row = mysqli_fetch_array($opt_query, MYSQLI_ASSOC)){ 
    $privacy_opt = $row["privacy_opt"];
}
if ($privacy_opt == "fri" && $id != "$logOptions_id" && $friendArray == "$logOptions_id"){
 
echo "Only this person's friend can see this information.";
} else {
echo $website, $youtube, $locationInfo;
}
?>

 

The $friendArray variable contains the users friends ID's in the form of 51, 100, 22, etc.

Link to comment
Share on other sites

@andy1212 they toggle through via a dropdown on their settings page.

 

If they want friends only to see info, then "fri" is added to privacy_opt field in the database. If they want public it is just left as empty.

Link to comment
Share on other sites

Ok I'm not very familiar with PDO and it looks like you're trying to accomplish this using PDO queries. I laid out how I would set up the functions, dropdown menu, grabbing the data from the database to show which option the user has selected and how to allow the user to send whatever option they choose to the database, which will update the option selected in the dropdown. I'm sure you can take the code I've shown and get an idea of how it should function and change some things to PDO where needed.
 
in your user.func.php file or where ever you're putting your functions, (remember if you're function is on a separate page, to include it on the page you want to use the function on.)
 
function user_data($id){
$args = func_get_args();
unset($args[0]);
$fields = '`'.implode('`, `', $args).'`';


$query = mysql_query("SELECT $fields FROM `user_optionsc0nf` WHERE `id`=".$_SESSION['id']) or die(mysql_error());
$query_result = mysql_fetch_assoc($query);
foreach ($args as $field) {
$args[$field] = $query_result[$field];
}
return $args;
}
on the page where the user chooses a privacy option, this code will select what option they chose so be it, select, public or friendsonly
 
$id = $_SESSION['id'];
$data = user_data($id, 'privacy_opt');
 

on the page where the user can choose which privacy option they want in the form.

<select name="privacydrop">
   <option value="select" <?php if ($data['privacy_opt'] == 'select') echo 'selected="selected"' ?>>Select a privacy option</option>
   <option value="public" <?php if ($data['privacy_opt'] == 'public') echo 'selected="selected"' ?>>Public</option>
   <option value="friendsonly" <?php if ($data['privacy_opt'] == 'friendsonly') echo 'selected="selected"' ?>>Friends Only</option>
</select>

on user.func.php page or seperate page

function update_user($privacy_opt) {
   $privacy_opt = mysql_real_escape_string($privacy_opt);
   mysql_query("UPDATE `user_optionsc0nf` SET `privacy_opt`='$privacy_opt' WHERE `id`=".$_SESSION['id']);
}
 

 

 

Code to perform the task of sending the chosen privacy option to the database to the field privacy_opt.

if (isset($_POST['privacydrop'])) {
   $privacydrop = $_POST['privacydrop'];

   $errors = array();

   if ($privacydrop == 'select') {
      $errors[] = 'You must select a privacy option';
   }

   if ($privacydrop == 'public') {
      $privacy_opt = 'public';
   }

   if ($privacydrop == 'friendsonly') {
      $privacy_opt = 'friendsonly';
   }

   if (!empty($errors)) {
      foreach ($errors as $error) {
         echo $error '<br />';
      }
   } else {
      update_user($privacy_opt);
      header('Location: whatever_your_page_is_called.php');
      exit();
   }
}
Edited by andy1212
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.