1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <?php ob_start();
mysql_connect("****", "****", "****");
mysql_select_db("****");
$retour_messages=mysql_query('SELECT * FROM membres');
while ($donnees = mysql_fetch_array($retour_messages))
{
if(strtolower($donnees['pseudo']) == strtolower($_COOKIE["pseudo"]) && md5($donnees['password']) == $_COOKIE["password"])
{
$id_co = $donnees['ID'];
$pseudo_co = $donnees['pseudo'];
$accepted = "ok";
}
}
if ($accepted == "ok")
{
$id_article = $_POST['articles'];
$retour_messages=mysql_query('SELECT * FROM news WHERE id LIKE "'.$id_article.'"');
while($donnees = mysql_fetch_array($retour_messages))
{
$char_act=0;
$char_prec=0;
$nb_like = $donnees['nb_aime'];
$like = $donnees['aime'];
$retourne = true;
while(strlen($like) != $char_act)
{
if(substr($like, $char_act, 1) == ",")
{
$char =$char_act-$char_prec;
$user = substr($like, $char_prec, $char);
if($id_co == $user)
{
$char1 = substr($like,0, $char_prec);
if($char_act+1 == strlen($like))
{
$char2 = "";
}
else
{
$char2 = substr($like,$char_act+1,strlen($like)-$char_act);
}
$retourne = false; //L'utilisateur est deja dans la liste des "j'aime"
}
$char_prec = $char_act+1;
}
$char_act = $char_act+1;
}
if($retourne == true)
{
if($like == NULL)
{
$like = $id_co.",";
}
else
{
$like = "".$like."".$id_co.",";
}
$nb_like = $nb_like+1;
mysql_query("UPDATE news SET aime='".$like."',nb_aime='".$nb_like."' WHERE id='".$id_article."'");
}
else
{
$nb_like = $nb_like-1;
$like = $char1.$char2;
mysql_query("UPDATE news SET aime='".$like."',nb_aime='".$nb_like."' WHERE id='".$id_article."'");
}
}
}
header("location:articles.php?articles=".$id_article."");
ob_end_flush();
?> |
Partager