Bonjour à tous,
Tout d'abord histoire de mettre les P autour du H j'y connais quasi rien en PHP... mas, comme on dit, faut bien commencer un jour.
Je m'explique:
Je voudrais mettre un système de notation via étoiles sur certaines pages. Je me suis servi de ce script :
5-STARS RATING
L'affichage marche bien, je sélectionne la note, une popup de remerciement pour le vote s'ouvre, et lorsque je clic sur OK il me renvoi une erreur 500 server internal error
Je ne vois pas trop ou ça bug, si ça viens du fichier rate.php ou takerate.php.
Dans les commentaire, un certains SINGSING a fait des modifs, j'ai essayé, mais toujours erreur 500
L'url qui plante donne : http://www.monsite.com/voteshttp://www.phpcs.com/infomsg.aspx?ajout=1/takerate.php?name=5starsdemo
Le code du fichier rate.php:
Code PHP :
<?
/*
PHPSOFT.ORG 5-STARS RATING SCRIPT !
Script developed by SqrtBoy (sqrtboy@phpsoft.org)
*/
function rate($name)
{
if (file_exists("./votes/$name.txt")) {
$fp = fopen("./votes/$name.txt", "r");
$ligne = fgets($fp,4096);
//we retrieve variables
$tt_votes = strrchr($ligne, "|");
$tt_votes = str_replace("|", "", $tt_votes);
$tt_votes = trim($tt_votes);
$ligne = strrev($ligne);
$nb_votes = strrchr($ligne, "|");
$nb_votes = strrev($nb_votes);
$nb_votes = str_replace("|", "", $nb_votes);
$nb_votes = trim($nb_votes);
fclose($fp);
// Calculs :
if (($tt_votes == 0) AND ($nb_votes == 0))
{
// Si fichier vide
$etoiles_oui = 0;
$note = "0.00";
}
else
{
$moy_en = $tt_votes/$nb_votes;
$etoiles = round($moy_en);
$note = round($moy_en, 2);
}
$Result = "<table border='0' width='100%' ><tr><td width='50%'>";
if ($nb_votes > 0)
{
$Result .="<img src=\"./votes/rating/".$etoiles."stars.gif\" border=\"0\" alt=\"Rate\">";
$Result .=" (<strong><font size=3>Ratings: ".$note." / 5</strong>";
$Result.=" - <strong>Votes: ".$nb_votes."</strong></font>)";
}
else $Result .="<font size=3><strong>No votes yet</strong></font> ";
if (!isset($_COOKIE[$name]))
{
$Result.="</td><form name=\"rate\" action=\"./votes/takerate.php?name=$name\" method=\"post\" onSubmit=\"alert('Thank you for voting!');\" > ";
$Result.="<td width=50% align=left><select name=\"note\">";
$Result.="<option value =\"5\">5 - Excellent !</option>";
$Result.="<option value =\"4\">4 - Very Good !</option>";
$Result.="<option value =\"3\">3 - Fair !</option>";
$Result.="<option value =\"2\">2 - Ok !</option>";
$Result.="<option value =\"1\">1 - Poor !</option>";
$Result.="<option value =\"0\">0 - Awful !</option>";
$Result.="</select>";
$Result.=" <input type=\"submit\" value=\"Rate\"></td></form>";
}
else
$Result.="<font size=3><strong> - You have already rated this software</strong></font>";
$Result.="</td></tr></table>";
}
else
{
$Result = "<table border='0' width='100%'><tr><td width=20%>";
$Result.="<strong><font size=3>No votes yet</font></strong></td><form name=\"rate\" action=\"./votes/takerate.php?name=$name\" method=\"post\" onSubmit=\"alert('Thank you for voting!');\" > ";
$Result.="<td width=80% align=left><select name=\"note\" style=\"margin: 0; font-size: 6 pt; font-family: Verdana; border: 0\">";
$Result.="<option value =\"5\">5 - Excellent !</option>";
$Result.="<option value =\"4\">4 - Very Good !</option>";
$Result.="<option value =\"3\">3 - Fair !</option>";
$Result.="<option value =\"2\">2 - Ok !</option>";
$Result.="<option value =\"1\">1 - Poor !</option>";
$Result.="<option value =\"0\">0 - Awful !</option>";
$Result.="</select>";
$Result.=" <input type=\"submit\" value=\"Rate\">";
$Result.="</td></form></tr></table>";
}
return $Result;
}
?>
Le code du fichier takerate.php:
Code PHP :
<?
if (isset($_COOKIE[$name]))
header("Location: ".$_SERVER['HTTP_REFERER']);
else
{
if (isset($name))
{
setcookie($name, $name, time()+60*60*24*30,"/");
if (file_exists("votes/$name.txt"))
{
$fp = fopen("votes/$name.txt", "r");
$ligne = fgets($fp,4096);
// Acquisition des variables
$tt_votes = strrchr($ligne, "|");
$tt_votes = str_replace("|", "", $tt_votes);
$tt_votes = trim($tt_votes);
$ligne = strrev($ligne);
$nb_votes = strrchr($ligne, "|");
$nb_votes = strrev($nb_votes);
$nb_votes = str_replace("|", "", $nb_votes);
$nb_votes = trim($nb_votes);
fclose($fp);
// Calculs
$nb_votes++;
$tt_votes = $tt_votes + $note;
}
// Création du fichier s'il n'existe pas
else
{
touch("votes/$name.txt");
$nb_votes = 1;
$tt_votes = $note;
}
// Ajout des données
$fp = fopen("votes/$name.txt","w");
fputs($fp, "$nb_votes|$tt_votes");
fclose($fp);
header("Location: ".$_SERVER['HTTP_REFERER']);
}
}
?>
D'après ce que je pense comprendre, ça ne viendrait pas de la variable $name ?
Merci à vous !