begin process at 2012 05 31 20:11:03
  Trouver un code source :
 
dans
 
Accueil > Forum > 

PHP

 > 

Divers

 > 

Aide & documentation

 > 

systeme d'ami


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

systeme d'ami

samedi 3 décembre 2011 à 17:12:25 | systeme d'ami

moza2409

Bonjour à tous,
Je recherche des explications ou un tuto sur la création d'un systeme d'ami(genre facebook).
J'ai essayé de suivre ce tuto. mais sans reussite.
Si quelqu'un pourrait m'expliquer la marche à suivre

Merci
dimanche 4 décembre 2011 à 23:15:05 | Re : systeme d'ami

moza2409

Personne pour m'aider
lundi 5 décembre 2011 à 11:20:41 | Re : systeme d'ami

coucou747

Administrateur CodeS-SourceS
Bonjour,

On ne peut pas t'expliquer grand chose sur le sujet sans écrire un livre complet.

Pose plus clairement ta question, explique là ou tu bloques.

Cordialement,

Maxime
lundi 5 décembre 2011 à 15:00:01 | Re : systeme d'ami

moza2409

Bonjour, donc en faite j'ai récuperé un petit script que j'ai un peut modifié pour pouvoir l'intégrer à mon site, mais le probleme c'est que quand je clique sur "Add as friend" ensuite sur "yes" rien ne se passe, je laisse les 2 pages de script au cas ou j'aurai fait une erreur.
Code PHP :
<?php

mysql_connect("localhost", "root", "pepepe");
mysql_select_db("test");

?>
<?php 
// ------- INITIALIZE SOME VARIABLES ---------
// they must be initialized in some server environments or else errors will get thrown
$id = "";
$firstname = "";
$user_pic = "";
$interactionBox = "";
$cacheBuster = rand(999999999,9999999999999); // Put on an image URL will help always show new when changed
$l=$_SESSION['valid'];

// ------- FILTER THE ID AND QUERY THE DATABASE --------
$id = preg_replace('#[^0-9]#i', '', $id); // filter everything but numbers on the ID just in case
$sql = mysql_query("SELECT * FROM client WHERE id='$m'"); // query the member

// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums

// ------- WHILE LOOP FOR GETTING THE MEMBER DATA ---------
while($row = mysql_fetch_array($sql)){ 
    $l = $row["login"];
	$firstname = $row["firstname"];
	if (!$l) {$l = $firstname;} // If username is blank use the firstname... programming changes in v1.32 call for this

	$sign_up_date = $row["sign_up_date"];
    $sign_up_date = strftime("%b %d, %Y", strtotime($sign_up_date));
	$last_log_date = $row["last_log_date"];
    $last_log_date = strftime("%b %d, %Y", strtotime($last_log_date));	

	$friend_array = $row["friend_array"];
	///////  Mechanism to Display Pic. See if they have uploaded a pic or not  //////////////////////////
	$check_pic = "members/$l/image01.jpg";
	$default_pic = "members/0/image01.jpg";
	if (file_exists($check_pic)) {
    $user_pic = "<img src=\"$check_pic?$cacheBuster\" width=\"218px\" />"; 
	} else {
	$user_pic = "<img src=\"$default_pic\" width=\"218px\" />"; 
	}
} 

// ------- ESTABLISH THE PROFILE INTERACTION TOKEN ---------
if (!isset($_SESSION['wipit'])) { // Check to see if session wipit is set yet
	session_register('wipit'); // Be sure to register the session if it is not set yet
}
$thisRandNum = rand(9999999999999,999999999999999999);
$_SESSION['wipit'] = base64_encode($thisRandNum);

// initialize some output variables
$friendLink = "";
$the_blab_form = "";
if (isset($_SESSION['valid']) && $logOptions_id = $l) { // If SESSION idx is set, AND it does not equal the profile owner's ID

	// SQL Query the friend array for the logged in viewer of this profile if not the owner
	$sqlArray = mysql_query("SELECT friend_array FROM client WHERE id='" . $logOptions_id ."' LIMIT 1"); 
	while($row=mysql_fetch_array($sqlArray)) { $iFriend_array = $row["friend_array"]; }
	 $iFriend_array = explode(",", $iFriend_array);
	if (in_array($l, $iFriend_array)) { 
	    $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 = '<br /><br /><div class="interactionLinksDiv">

		  ' . $friendLink . ' 
          <a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'private_message\');">Message</a>
          </div><br />';

		  $the_blab_form = '<div style="background-color:#B7DBFF; border:#999 1px solid; padding:8px;">

          <textarea name="blab_field" rows="3" style="width:99%;"></textarea>
          <strong>Write on ' . $l . '\'s Board (coming soon)</strong>

          </div>';

} else if (isset($_SESSION['valid']) && $logOptions_id == $l) { // If SESSION idx is set, AND it does equal the profile owner's ID
	$interactionBox = '<br /><br /><div class="interactionLinksDiv">

           <a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'friend_requests\');">Friend Requests</a>
          </div><br />';

		  $the_blab_form = ' ' . $blab_outout_msg . '

          <div style="background-color:#D2F0D3; border:#999 1px solid; padding:8px;">
          <form action="mesami.php" method="post" enctype="multipart/form-data" name="blab_from">
          <textarea name="blab_field" rows="3" style="width:99%;"></textarea>
		  <input name="blabWipit" type="hidden" value="' . $thisRandNum . '" />
          <strong>Blab away ' . $l . '</strong> (220 char max) <input name="submit" type="submit" value="Blab" />
          </form></div>';

} else { // If no SESSION id is set, which means we have a person who is not logged in
	$interactionBox = '<div style="border:#CCC 1px solid; padding:5px; background-color:#E4E4E4; color:#999; font-size:11px;">

           <a href="register.php">Sign Up</a> or <a href="login.php">Log In</a> to interact with ' . $l . '
          </div>';

		  $the_blab_form = '<div style="background-color:#D2F0D3; border:#999 1px solid; padding:8px;">

          <textarea name="blab_field" rows="3" style="width:99%;"></textarea>
          <a href="register.php">Sign Up</a> or <a href="login.php">Log In</a> to write on ' . $l . '\'s Board

          </div>';

}

// ------- POPULATE FRIEND DISPLAY LISTS IF THEY HAVE AT LEAST ONE FRIEND -------------------
$friendList = "";
$friendPopBoxList = "";
if ($friend_array  = "") { 
	// ASSEMBLE FRIEND LIST AND LINKS TO VIEW UP TO 6 ON PROFILE
	$friendArray = explode(",", $friend_array);
	$friendCount = count($friendArray);
    $friendArray6 = array_slice($friendArray, 0, 6);
	
	$friendList .= '<div class="infoHeader">' . $l . '\'s Friends (<a href="#" onclick="return false" onmousedown="javascript:toggleViewAllFriends(\'view_all_friends\');">' . $friendCount . '</a>)</div>';
    $i = 0; // create a varible that will tell us how many items we looped over 
	 $friendList .= '<div class="infoBody"><table id="friendTable" align="center" cellspacing="4"></tr>'; 
    foreach ($friendArray6 as $key => $value) { 
        $i++; // increment $i by one each loop pass 
		$check_pic = 'members/' . $value . '/image01.jpg';
		    if (file_exists($check_pic)) {
				$frnd_pic = '<a href="mesami.php?id=' . $value . '"><img src="' . $check_pic . '" width="54px" border="1"/></a>';
		    } else {
				$frnd_pic = '<a href="mesami.php?id=' . $value . '"><img src="members/0/image01.jpg" width="54px" border="1"/></a> &nbsp;';
		    }
			$sqlName = mysql_query("SELECT login FROM client WHERE id='$value' LIMIT 1") or die ("Sorry we had a mysql error!");
		    while ($row = mysql_fetch_array($sqlName)) { $friendUserName = substr($row["login"],0,12);}
			if (!$friendUserName) {$friendUserName = $friendFirstName;} // If username is blank use the firstname... programming changes in v1.32 call for this
			if ($i % 6 == 4){
				$friendList .= '<tr><td><div style="width:56px; height:68px; overflow:hidden;" title="' . $friendUserName . '">

				<a href="mesami.php?id=' . $value . '">' . $friendUserName . '</a><br />' . $frnd_pic . '
				</div></td>';  

			} else {
				$friendList .= '<td><div style="width:56px; height:68px; overflow:hidden;" title="' . $friendUserName . '">

				<a href="mesami.php?id=' . $value . '">' . $friendUserName . '</a><br />' . $frnd_pic . '
				</div></td>'; 

			}
    } 
	 $friendList .= '</tr></table>

	 <div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleViewAllFriends(\'view_all_friends\');">view all</a></div>
	 </div>'; 

	// END ASSEMBLE FRIEND LIST... TO VIEW UP TO 6 ON PROFILE
	// ASSEMBLE FRIEND LIST AND LINKS TO VIEW ALL(50 for now until we paginate the array)
	$i = 0;
	$friendArray50 = array_slice($friendArray, 0, 50);
	$friendPopBoxList = '<table id="friendPopBoxTable" width="100%" align="center" cellpadding="6" cellspacing="0">';
	foreach ($friendArray50 as $key => $value) { 
        $i++; // increment $i by one each loop pass 
		$check_pic = 'members/' . $value . '/image01.jpg';
		    if (file_exists($check_pic)) {
				$frnd_pic = '<a href="mesami.php?id=' . $value . '"><img src="' . $check_pic . '" width="54px" border="1"/></a>';
		    } else {
				$frnd_pic = '<a href="mesami.php?id=' . $value . '"><img src="members/0/image01.jpg" width="54px" border="1"/></a> &nbsp;';
		    }
			$sqlName = mysql_query("SELECT login FROM client WHERE id='$value' LIMIT 1") or die ("Sorry we had a mysql error!");
		    while ($row = mysql_fetch_array($sqlName)) { $funame = $row["login"]; }
			if (!$funame) {$funame = $ffname;} // If username is blank use the firstname... programming changes in v1.32 call for this
				if ($i % 2) {
					$friendPopBoxList .= '<tr bgcolor="#F4F4F4"><td width="14%" valign="top">

					<div style="width:56px; height:56px; overflow:hidden;" title="' . $funame . '">' . $frnd_pic . '</div></td>
				     <td width="86%" valign="top"><a href="mesami.php?id=' . $value . '">' . $funame . '</a><br /><font size="-2"><em>' . $fcity . '<br />' . $fstate . '<br />' . $fcountry . '</em></font></td>
				    </tr>';  

				} else {
				    $friendPopBoxList .= '<tr bgcolor="#E0E0E0"><td width="14%" valign="top">

					<div style="width:56px; height:56px; overflow:hidden;" title="' . $funame . '">' . $frnd_pic . '</div></td>
				     <td width="86%" valign="top"><a href="mesami.php?id=' . $value . '">' . $funame . '</a><br /><font size="-2"><em>' . $fcity . '<br />' . $fstate . '<br />' . $fcountry . '</em></font></td>
				    </tr>';  

				}
    } 
	$friendPopBoxList .= '</table>';
	// END ASSEMBLE FRIEND LIST AND LINKS TO VIEW ALL(50 for now until we paginate the array)
}
// ------- END POPULATE FRIEND DISPLAY LISTS IF THEY HAVE AT LEAST ONE FRIEND -------------------
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Description" content="Profile for <?php echo "$l"; ?>" />
<meta name="Keywords" content="<?php echo "$l"; ?>" />
<meta name="rating" content="General" />
<meta name="ROBOTS" content="All" />
<title>Site Profile for <?php echo "$l"; ?></title>
<link href="style/main.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<script src="jquery-1.4.2.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript">
// jQuery functionality for toggling member interaction containers
function toggleInteractContainers(x) {
		if ($('#'+x).is(":hidden")) {
			$('#'+x).slideDown(200);
		} else {
			$('#'+x).hide();
		}
		$('.interactContainers').hide();
}
function toggleViewAllFriends(x) {
		if ($('#'+x).is(":hidden")) {
			$('#'+x).fadeIn(200);
		} else {
			$('#'+x).fadeOut(200);
		}
}

// Friend adding and accepting stuff
var thisRandNum = "<?php echo $thisRandNum; ?>";
var friendRequestURL = "request_as_friend.php";
function addAsFriend(a,b) {

	$("#add_friend_loader").show();
	$.post(friendRequestURL,{ request: "requestFriendship", mem1: a, mem2: b, thisWipit: thisRandNum } ,function(data) {
	    $("#add_friend").html(data).show().fadeOut(12000);
    });	
}


function acceptFriendRequest (x) {
	$.post(friendRequestURL,{ request: "acceptFriend", reqID: x, thisWipit: thisRandNum } ,function(data) {
            $("#req"+x).html(data).show();
    });
}
function denyFriendRequest (x) {
	$.post(friendRequestURL,{ request: "denyFriend", reqID: x, thisWipit: thisRandNum } ,function(data) {
           $("#req"+x).html(data).show();
    });
}
// End Friend adding and accepting stuff
// Friend removal stuff
function removeAsFriend(a,b) {
	$("#remove_friend_loader").show();
	$.post(friendRequestURL,{ request: "removeFriendship", mem1: a, mem2: b, thisWipit: thisRandNum } ,function(data) {
	    $("#remove_friend").html(data).show().fadeOut(12000);
    });	
}
// End Friend removal stuff
</script>
</head>
<body>

<table class="mainBodyTable" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="738" valign="top"><br />
      <table width="98%" border="0" align="center" cellpadding="6">
      <tr>
        <td width="33%" valign="top">
          <?php echo $user_pic; ?>
          <div class="infoHeader"><?php echo $l; ?>'s Information</div>
          <div class="infoBody">
          </div>		  	
          <?php echo $friendList; ?>
		  
          <div id="view_all_friends">
              <div align="right" style="padding:6px; background-color:#FFF; border-bottom:#666 1px solid;">
                       <div style="display:inline; font-size:14px; font-weight:bold; margin-right:150px;">All Friends</div> 
                       <a href="#" onclick="return false" onmousedown="javascript:toggleViewAllFriends('view_all_friends');">close </a>
              </div>
              <div style="background-color:#FFF; height:240px; overflow:auto;">
                   <?php echo $friendPopBoxList; ?>
              </div>
              <div style="padding:6px; background-color:#000; border-top:#666 1px solid; font-size:10px; color: #0F0;">
                       Temporary programming shows 50 maximum. Navigating through the full list is coming soon.
              </div>
         </div>
          <div class="infoBody" style="border-bottom:#999 1px solid;"></div>    
          <br />
          </td>
        <td width="67%" valign="top">
          <span style="font-size:16px; font-weight:800;"><?php echo "$l"; ?></span>
		 
		  <?php echo $interactionBox; ?>
 
          <div class="interactContainers" id="add_friend">
                <div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers('add_friend');">cancel</a> </div>
                Add <?php echo "$l"; ?> as a friend? &nbsp;
                <a href="#" onclick="return false" onmousedown="javascript:addAsFriend(<?php echo $logOptions_id; ?>, <?php echo $l; ?>);">Yes</a>
                <span id="add_friend_loader"><img src="img/loading.gif" width="28" height="10" alt="Loading" /></span>
          </div>
          
          <div class="interactContainers" id="remove_friend">
                <div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers('remove_friend');">cancel</a> </div>
                Remove <?php echo "$l"; ?> from your friend list? &nbsp;
                <a href="#" onclick="return false" onmousedown="javascript:removeAsFriend(<?php echo $logOptions_id; ?>, <?php echo $l; ?>);">Yes</a>
                <span id="remove_friend_loader"><img src="img/loading.gif" width="28" height="10" alt="Loading" /></span>
          </div>
          
          <div class="interactContainers" id="private_message">
          Private Messaging Will Go Here When It Is Ready
          </div>
          
          <div class="interactContainers" id="friend_requests" style="background-color:#FFF; height:240px; overflow:auto;">
            <div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers('friend_requests');">close window</a> &nbsp; &nbsp; </div>
            <h3>The following people are requesting you as a friend</h3>
    <?php 
    $sql = "SELECT * FROM friends_requests WHERE mem2='$l' ORDER BY id ASC LIMIT 50";
	$query = mysql_query($sql) or die ("Sorry we had a mysql error!");
	$num_rows = mysql_num_rows($query); 
	if ($num_rows < 1) {
		echo 'You have no Friend Requests at this time.';
	} else {
        while ($row = mysql_fetch_array($query)) { 
		    $requestID = $row["id"];
		    $mem1 = $row["mem1"];
	        $sqlName = mysql_query("SELECT login FROM client WHERE id='$mem1' LIMIT 1") or die ("Sorry we had a mysql error!");
		    while ($row = mysql_fetch_array($sqlName)) { $requesterUserName = $row["login"]; }
		    ///////  Mechanism to Display Pic. See if they have uploaded a pic or not  //////////////////////////
		    $check_pic = 'members/' . $mem1 . '/image01.jpg';
		    if (file_exists($check_pic)) {
				$lil_pic = '<a href="mesami.php?id=' . $mem1 . '"><img src="' . $check_pic . '" width="50px" border="0"/></a>';
		    } else {
				$lil_pic = '<a href="mesami.php?id=' . $mem1 . '"><img src="members/0/image01.jpg" width="50px" border="0"/></a>';
		    }
		    echo	'<hr />

<table width="100%" cellpadding="5"><tr><td width="17%" align="left"><div style="overflow:hidden; height:50px;"> ' . $lil_pic . '</div></td>
                        <td width="83%"><a href="mesami.php?id=' . $mem1 . '">' . $requesterUserName . '</a> wants to be your Friend!<br /><br />
					    <span id="req' . $requestID . '">
					    <a href="#" onclick="return false" onmousedown="javascript:acceptFriendRequest(' . $requestID . ');" >Accept</a>
					    &nbsp; &nbsp; OR &nbsp; &nbsp;
					    <a href="#" onclick="return false" onmousedown="javascript:denyFriendRequest(' . $requestID . ');" >Deny</a>
					    </span></td>
                        </tr>
                       </table>';

        }	 
	}
    ?>
          </div>
          
            <?php echo $the_blab_form; ?>
          
     

          </td>
      </tr>
      </table>
      <p><br />
        <br />
      </p></td>
    <td width="160" valign="top"><br /><br /></td>
  </tr>
</table>

</body>
</html>


Code PHP :
<?php

mysql_connect("localhost", "root", "pepepe");
mysql_select_db("test");


if (!isset($_SESSION['valid']) || !isset($_SESSION['valid'])) 
	echo  'Error: Your session expired from inactivity. Please refresh your browser and continue.';
    exit();

if ($sessWipit != $thisWipit) {
	echo  'Error: Forged submission';
    exit();
}

if ($thisWipit == "") {
	echo  'Error: Missing Data';
    exit();
}

include_once "dbcon.php"; // <<---- Connect to database here
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////                                                                    PART 1                                                               //////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ($_POST["request"] = "requestFriendship") {
	
    $mem1 = preg_replace('#[^0-9]#i', '', $_POST['mem1']); 
    $mem2 = preg_replace('#[^0-9]#i', '', $_POST['mem2']); 
	//
	if (!$mem1 || !$mem2 || !$thisWipit) {
		echo  'Error: Missing data';
    	exit(); 
	}
	//
	if ($mem1 == $mem2) {
    	echo  'Error: You cannot add yourself as a friend';
    	exit(); 
	} 
	
	$sql_frnd_arry_mem1 = mysql_query("SELECT friend_array FROM client WHERE id='$mem1' LIMIT 1"); 
	while($row=mysql_fetch_array($sql_frnd_arry_mem1)) { $frnd_arry_mem1 = $row["friend_array"]; }
	$frndArryMem1 = explode(",", $frnd_arry_mem1);
    if (in_array($mem2, $frndArryMem1)) { echo  'This member is already your Friend'; exit(); }

	$sql = mysql_query("SELECT id FROM friends_requests WHERE mem1='$mem1' AND mem2='$mem2' Limit 1");
	$numRows = mysql_num_rows($sql);
	if ($numRows > 0) {
		echo '<img src="images/round_error.png" width="20" height="20" alt="Error" /> You have a Friend request pending for this member. Please be patient.';
        exit(); 
	}
	$sql = mysql_query("SELECT id FROM friends_requests WHERE mem1='$mem2' AND mem2='$mem1' Limit 1");
	$numRows = mysql_num_rows($sql);
	if ($numRows > 0) {
		echo '<img src="images/round_error.png" width="20" height="20" alt="Error" /> This user has requested you as a Friend already! Check your Requests on your profile.';
        exit(); 
	}
	$sql = mysql_query("INSERT INTO friends_requests (mem1, mem2, timedate) VALUES('$mem1','$mem2',now())") or die (mysql_error("Friend Request Insertion Error"));
	//$sql = mysql_query("INSERT INTO pms (to, from, time, sub, msg) VALUES('$mem2','XXXXX',now(),'New Friend Request','You have a new Friend Request waiting for approval.<br /><br />Navigate to your  and check your friend requests. <br /><br />Thank you.')") or die (mysql_error("Friend Request PM Insertion Error"));
    //$id = mysql_insert_id();
	echo '<img src="images/round_success.png" width="20" height="20" alt="Success" /> Friend request sent successfully. This member must approve the request.';
    exit(); 
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////                                                                    PART 2                                                               //////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ($_POST["request"] == "acceptFriend") {
	
    $reqID = preg_replace('#[^0-9]#i', '', $_POST['reqID']);
	$sql = "SELECT * FROM friends_requests WHERE id='$reqID' LIMIT 1";
	$query = mysql_query($sql) or die ("Sorry we had a mysql error!");
	$num_rows = mysql_num_rows($query); 
	if ($num_rows < 1) {
		echo 'An error occured';
		exit();
	}
    while ($row = mysql_fetch_array($query)) { 
		$mem1 = $row["mem1"];
		$mem2 = $row["mem2"];
    }
	$sql_frnd_arry_mem1 = mysql_query("SELECT friend_array FROM client WHERE id='$mem1' LIMIT 1"); 
	$sql_frnd_arry_mem2 = mysql_query("SELECT friend_array FROM client WHERE id='$mem2' LIMIT 1"); 
	while($row=mysql_fetch_array($sql_frnd_arry_mem1)) { $frnd_arry_mem1 = $row["friend_array"]; }
	while($row=mysql_fetch_array($sql_frnd_arry_mem2)) { $frnd_arry_mem2 = $row["friend_array"]; }
	$frndArryMem1 = explode(",", $frnd_arry_mem1);
	$frndArryMem2 = explode(",", $frnd_arry_mem2);
    if (in_array($mem2, $frndArryMem1)) { echo  'This member is already your Friend'; exit(); }
	if (in_array($mem1, $frndArryMem2)) { echo  'This member is already your Friend'; exit(); }
	if ($frnd_arry_mem1 != "") { $frnd_arry_mem1 = "$frnd_arry_mem1,$mem2"; } else { $frnd_arry_mem1 = "$mem2"; }
	if ($frnd_arry_mem2 != "") { $frnd_arry_mem2 = "$frnd_arry_mem2,$mem1"; } else { $frnd_arry_mem2 = "$mem1"; }
    $UpdateArrayMem1 = mysql_query("UPDATE client SET friend_array='$frnd_arry_mem1' WHERE id='$mem1'") or die (mysql_error());
    $UpdateArrayMem2 = mysql_query("UPDATE client SET friend_array='$frnd_arry_mem2' WHERE id='$mem2'") or die (mysql_error());
	$deleteThisPendingRequest = mysql_query("DELETE FROM friends_requests WHERE id='$reqID' LIMIT 1"); 
    echo "You are now friends with this member!";
	exit();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////                                                                    PART 3                                                               //////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ($_POST["request"] == "denyFriend") {
	$reqID = preg_replace('#[^0-9]#i', '', $_POST['reqID']);
	$deleteThisPendingRequest = mysql_query("DELETE FROM friends_requests WHERE id='$reqID' LIMIT 1"); 
    echo "Request Denied";
	exit();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////                                                                    PART 4                                                               //////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ($_POST["request"] == "removeFriendship") {
	
	$mem1 = preg_replace('#[^0-9]#i', '', $_POST['mem1']); // Person doing the friendship remove
    $mem2 = preg_replace('#[^0-9]#i', '', $_POST['mem2']);  // Person being removed
	//
	if (!$mem1 || !$mem2 || !$thisWipit) {
		echo  'Error: Missing data';
    	exit(); 
	}
	//
	$decryptedID = base64_decode($_SESSION['valid']);
	$id_array = explode("p3h9xfn8sq03hs2234", $decryptedID);
	$mem1SessIDX = $id_array[1];
	if ($mem1SessIDX != $mem1) {
    	exit();
	}
    // Query mem1 and mem2 friend_array out of DB
	$sql_frnd_arry_mem1 = mysql_query("SELECT friend_array FROM client WHERE id='$mem1' LIMIT 1"); 
	$sql_frnd_arry_mem2 = mysql_query("SELECT friend_array FROM client WHERE id='$mem2' LIMIT 1"); 
	while($row=mysql_fetch_array($sql_frnd_arry_mem1)) { $frnd_arry_mem1 = $row["friend_array"]; }
	while($row=mysql_fetch_array($sql_frnd_arry_mem2)) { $frnd_arry_mem2 = $row["friend_array"]; }
	// Check to see they are in fact each other's friends
	$frndArryMem1 = explode(",", $frnd_arry_mem1);
	$frndArryMem2 = explode(",", $frnd_arry_mem2);
    if (!in_array($mem2, $frndArryMem1)) { echo  'This member is not in your list'; exit(); }
	if (!in_array($mem1, $frndArryMem2)) { echo  'This member is not in your list'; exit(); }
	
	// Here we remove them from each other's arrays using "unset" on the key where the value is found
	foreach ($frndArryMem1 as $key => $value) {
			  if ($value == $mem2) {
			      unset($frndArryMem1[$key]);
			  } 
    }
	foreach ($frndArryMem2 as $key => $value) {
			  if ($value == $mem1) {
			      unset($frndArryMem2[$key]);
			  } 
    } 
	// Now implode the adjusted arrays to make them strings again before going into the database
	$newStringForMem1 = implode(",", $frndArryMem1);
    $newStringForMem2 =  implode(",", $frndArryMem2);
	// And now update their database fields
	$sql = mysql_query("UPDATE client SET friend_array='$newStringForMem1' WHERE id='$mem1'");
	$sql = mysql_query("UPDATE client SET friend_array='$newStringForMem2' WHERE id='$mem2'");
	echo 'You are no longer friends with this member.';
    exit(); 
}



Voila, merci
mercredi 7 décembre 2011 à 22:16:17 | Re : systeme d'ami

moza2409

personne ?


Cette discussion est classée dans : systeme, url, tuto, ami, suivre


Répondre à ce message

Sujets en rapport avec ce message

systeme d'ami [ par moza2409 ] Bonjour, je cherche à faire un module de systeme d'ami (du genre facebook). Donc je souhaiterais que les utilisateurs puisse ajouter d'autre utilisat Comparaison URL PHP [ par vargas ] Bonjour tout le monde J'ai une question toute bête, mais je ne trouve pas la solution. Voila j'ai besoin de comparer deux URL pour faire une conditio extraction d'images apartir d'un site web en php [ par mloukaddi ] salut tous ! et merci avant tous pour le site :: j'arive a une etape imprtant pour l'extraction de tous les image d'une page web en php !j'ai le code [clos] HELP ME Insertion id et chargement image URL avec MySql Urgent projet en cours [ par chhempo ] Bonjour, Je suis débutante en programmation php/mySQL et je ne sais pas comment faire la chose suivante [^^sad1]: Je dispose de 3 sites Web et dans ce afficher un planning des réservations de véhicules [ par pierre3401 ] Bonjour, J'ai réalisé, sur base du script de [url=http://www.phpcs.com/auteur/ZAKMANENGINEER/1105991.aspx]zakmanengineer [/url], un système de réserv url [ par paluma ] bonjour; je veut creer un fichieer .htaccess. Comment le faire? je veut avoir un url merci et à cordialement URL Rewritting + MVC + POO [ par BioSs007 ] Bonjour, J'aurais aimé savoir si quelqu'un maitrisait bien le sujet URL rewritting + MVC + POO car je n'arrive pas à rediriger mes adresses et mes fo Générer un nombre aléatoire [ par Mikonyx ] slt,pour générer un nombre aléatoire, j'utilise la commande:srand(time());$url=rand(1,$x);echo $url; $x ayant été déjà défini avant...Ca fonctionne, m nouveau site [ par vinceoli ] Voilà j'ai fait un site sur php et javascript qui est presque finit j'espère que vous y ferez un tour Mercihttp://www.vinceoli.fr.st Forum ? [ par Michael ] Quelqu'un sait comment marche le forum de arnotic ? Je comprends rienQuand je lance index.php3, j'ai une page blanche ! (j'ai essayé avec easyphp et s


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,874 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales