只允许朋友在个人资料页面中发表评论

时间:2013-05-17 23:01:59

标签: php mysql

我有一个包含评论系统的个人资料页面,我只是允许个人资料的所有者现在写他们的评论我想让朋友们也写这个怎么做?

在成员表中我有一个friend_array字段,其中包含与该用户成为朋友的用户的ID

朋友请求系统包括ajax和jquery

code.php

$blab_form="";
if(isset($_SESSION['user_id']))
{
  if($_SESSION['user_id']==$id)
  {
    $blab_form='
    '.$blab_output_msg.'<br />
                <div style="background-color:#D2F0D3;border:#999 1px solid; padding:8px;">
                <form action="profile.php" method="post" enctype="multipart/form-data" name="blab_form">
                      <textarea name="blab_field" cols="" rows="4"  style="width:100%;">
                      </textarea><br />
                      (220 Char Max)
                      <input type="submit" name="submit" value="Blab"/>
                </form></div>';
        //$sql = mysql_query("DELETE FROM blabing WHERE u_id ='$id'")or die(mysql_error());
  }
}

friend_request_system

<?php 
//****************friend request system********************//
// for securing the request with  and encryption to be  more secure.
if(isset($_SESSION['wpit']))
{
    $_SESSION['wipt'];
}
$theRundomNum = rand(99999999999999,9999999999999);
$_SESSION['wipt'] = base64_encode($theRundomNum);

//*********for distinguich the users*************//
//if member is a viewer
$friendLink = "";
if(isset($_SESSION['user_id'])&&$_SESSION['user_id']!=$id)
{
     //for quering friend array  for the viewer if he is not the owner 
     $sqlArray = mysql_query("SELECT  friend_array FROM members WHERE user_id ='".$_SESSION['user_id']."' LIMIT 1")or die(mysql_error());
     while($row = mysql_fetch_array($sqlArray))
     {
         $iFriendArray = $row['friend_array'];
     }
     $iFriendArray = explode("," , $iFriendArray);
     if(in_array($id, $iFriendArray))
     {
         $friendLink = '<a href="#" onclick = "return false" onmousedown="javascript:toggleInteractContainers(\'remove_friend\');">Remove Friend</a>';
     }
     else
     {
         $friendLink = '<a href="#" onclick = "return false" onmousedown="javascript:toggleInteractContainers(\'add_friend\');">Add as Friend</a>';
     }
    $interactionBox='<div class="interactionLinksDiv">
     '.$friendLink.' 
    </div>';
}
//if member is the profile ower
else
{
    $interactionBox = '<div class="interactionLinksDiv">
     <a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'friend_requests\');">Freind Request List</a> </div>';

}
?>

1 个答案:

答案 0 :(得分:1)

if($_SESSION['user_id']==$id)特定于博客所有者,对吗?因此,如果会话ID在可接受id的数组中,则进行此条件检查。像这样:

// assuming you already populated the $iFriendArray as outlined in your question
$iFriendArray[] = $id; // add blog owner to the friend array


if(in_array($_SESSION['user_id'], $iFriendArray))
{
    // can comment
}

这已更新为使用您问题中更新的好友数组。

任何问题随时可以提出,我可能会更新。