<?php
$voted = $_COOKIE["explosive_voted"]; //explosive_voted is the cookie that tells the script whether the user voted
if ($voted==0){
$fp = fopen ("rating.txt", "r"); $fr = fopen ("votes.txt", "r"); $ratingaverage = ((int)($rating)/(int)($votes));
$totalaverage = round($ratingaverage*2
)/2; if ($totalaverage > 0.5){
echo "<br>Based on ".$votes." votes.<br>"; echo "<img src=".$totalaverage.".png height=20>"; }
echo "<br>Vote Below<br>"; $fp = fopen ("stars.txt", "r"); $stars = fread ($fp, filesize ("stars.txt")); //stars.txt contains the html code for the form and is also where explosive_voted cookie is created }
if ($voted==1){
$refresh = $_COOKIE["explosive_refresh"];
if ($refresh==0){ //this should be execeuted the first time the page refreshes after the user voted
$fp = fopen ("rating.txt", "r"); $rating = $_POST['rating'];
$new = $original + $rating;
$ft = fopen ("rating.txt", "w"); $fr = fopen ("votes.txt", "r"); $newvotes = $originalvotes + 1;
$fw = fopen ("votes.txt", "w"); $ratingaverage = ((int)($new)/(int)($newvotes));
$totalaverage = round($ratingaverage*2
)/2; if ($totalaverage > 0.5){
echo "<br>Based on ".$newvotes." votes.<br>"; echo "<img src=".$totalaverage.".png height=20>"; }//creating the new cookie "explosive_refresh" with value "1" should probably go somewhere in this scope.
//Once the value is set to "1" this scope will never be executed for this session.
//I couldn't create a cookie here because it modified the if statement header info and gave me an error
if ($refresh==1){
$fp = fopen ("rating.txt", "r"); $fr = fopen ("votes.txt", "r"); $ratingaverage = ((int)($rating)/(int)($votes));
$totalaverage = round($ratingaverage*2
)/2; if ($totalaverage > 0.5){
echo "<br>Based on ".$votes." votes.<br>"; echo "<img src=".$totalaverage.".png height=20>"; }
}
}
}
?>
Tylko go dostosować lekko i po problemie. Źródło z forum macosxhints.com