Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> 5 gwiazdkowy system oceniania.
Mateusz10
post 11.08.2009, 11:16:01
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 25.04.2009

Ostrzeżenie: (0%)
-----


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.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
kilab
post 11.08.2009, 13:46:29
Post #2





Grupa: Zarejestrowani
Postów: 180
Pomógł: 19
Dołączył: 4.11.2007

Ostrzeżenie: (0%)
-----


  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

Ten post edytował kilab 11.08.2009, 13:51:21


--------------------
Go to the top of the page
+Quote Post
skowron-line
post 11.08.2009, 13:57:30
Post #3





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

Ostrzeżenie: (0%)
-----


http://gr0w.com/articles/code/php_5_star_r..._using_hreview/
lenistwo
http://www.google.pl/search?hl=pl&q=5+...=Szukaj&lr=


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 05:13