Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: 5 gwiazdkowy system oceniania.
Forum PHP.pl > Forum > Gotowe rozwiązania > Szukam
Mateusz10
Witam!
Chciałbym żebyście mi pomogli stworzyc lub dac gotowca skryptu php dzięki któremu na stronie można będzie głosowac. Dokładniej chodzi mi o coś takiego jak na youtube.com chcę również żeby głosy zapisywało do pliku tekstowego bez używania bazy danych. I jeżeli jest to możliwe chciałbym żeby była tam blokada ciasteczek aby nie było można głosowac w przeciągu 1minuty.

Z góry dziękuje.
kilab
  1. <?php
  2. $voted = $_COOKIE["explosive_voted"]; //explosive_voted is the cookie that tells the script whether the user voted
  3. if ($voted==0){
  4. $fp = fopen ("rating.txt", "r");
  5. $rating = fread ($fp, filesize ("rating.txt"));
  6. fclose($fp);
  7. $fr = fopen ("votes.txt", "r");
  8. $votes = fread ($fr, filesize ("votes.txt"));
  9. fclose($fr);
  10. $ratingaverage = ((int)($rating)/(int)($votes));
  11. $totalaverage = round($ratingaverage*2)/2;
  12. if ($totalaverage > 0.5){
  13. echo "<br>Based on ".$votes." votes.<br>";
  14. echo "<img src=".$totalaverage.".png height=20>";
  15. }
  16. echo "<br>Vote Below<br>";
  17. $fp = fopen ("stars.txt", "r");
  18. $stars = fread ($fp, filesize ("stars.txt")); //stars.txt contains the html code for the form and is also where explosive_voted cookie is created
  19. fclose($fp);
  20. echo $stars;
  21. }
  22.  
  23.  
  24. if ($voted==1){
  25. $refresh = $_COOKIE["explosive_refresh"];
  26. if ($refresh==0){ //this should be execeuted the first time the page refreshes after the user voted
  27. $fp = fopen ("rating.txt", "r");
  28. $original = fread ($fp, filesize ("rating.txt"));
  29. fclose($fp);
  30. $rating = $_POST['rating'];
  31. $new = $original + $rating;
  32. $ft = fopen ("rating.txt", "w");
  33. fwrite ($ft, $new);
  34. fclose($ft);
  35. $fr = fopen ("votes.txt", "r");
  36. $originalvotes = fread ($fr, filesize ("votes.txt"));
  37. $newvotes = $originalvotes + 1;
  38. $fw = fopen ("votes.txt", "w");
  39. fwrite ($fw, $newvotes);
  40. fclose($fw);
  41. $ratingaverage = ((int)($new)/(int)($newvotes));
  42. $totalaverage = round($ratingaverage*2)/2;
  43. if ($totalaverage > 0.5){
  44. echo "<br>Based on ".$newvotes." votes.<br>";
  45. echo "<img src=".$totalaverage.".png height=20>";
  46. }//creating the new cookie "explosive_refresh" with value "1" should probably go somewhere in this scope.
  47. //Once the value is set to "1" this scope will never be executed for this session.
  48. //I couldn't create a cookie here because it modified the if statement header info and gave me an error
  49.  
  50. if ($refresh==1){
  51. $fp = fopen ("rating.txt", "r");
  52. $rating = fread ($fp, filesize ("rating.txt"));
  53. fclose($fp);
  54. $fr = fopen ("votes.txt", "r");
  55. $votes = fread ($fr, filesize ("votes.txt"));
  56. fclose($fr);
  57. $ratingaverage = ((int)($rating)/(int)($votes));
  58. $totalaverage = round($ratingaverage*2)/2;
  59. if ($totalaverage > 0.5){
  60. echo "<br>Based on ".$votes." votes.<br>";
  61. echo "<img src=".$totalaverage.".png height=20>";
  62. }
  63. }
  64. }
  65. }
  66. ?>


Tylko go dostosować lekko i po problemie. Źródło z forum macosxhints.com
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.