PHP ver gevorderde |
|
ik heb een poll script gemaakt en nu wordt er wel een cookie weggeschreven maar ik weet niet of het script het cookie goed leest want ik krijg steeds de waarde false terug.:
<html>
<head>
<title>Poll</title>
</head>
<body>
<?php
$opties[0] = "<font face=verdana size=2>mooi ";
$opties[1] = "<font face=verdana size=2>gaat ";
$opties[2] = "<font face=verdana size=2>stom ";
$vraag = "<center><font face=verdana size=2>Wat vind je van de poll?</center>";
$result="result.txt";
$pointer=fopen($result,"r");
$poll=fread($pointer,filesize($result));
fclose($pointer);
$poll=explode(",",$poll);
$totaal=$poll[0]+$poll[1]+$poll[2];
$barlengte=400;
$barlengte0=(100/$totaal)*$poll[0];
$barlengte1=(100/$totaal)*$poll[1];
$barlengte2=(100/$totaal)*$poll[2];
$barlengte0=round($barlengte0);
$barlengte1=round($barlengte1);
$barlengte2=round($barlengte2);
$pro[0]=round(100/$totaal*$poll[0]);
$pro[1]=round(100/$totaal*$poll[1]);
$pro[2]=round(100/$totaal*$poll[2]);
if(isset($gestemd))
{
echo "<TABLE border=1 bordercolor=#000000 cellspacing=2 cellpadding=2 STYLE=\"border-style: solid; border-color: #ffffff;\" width=250><TR><TD STYLE=\"border-style: solid; border-color: #000000;\" width=500 colspan=2 style=\"filter:progid:DXImagetransform.Microsoft.Gradient(endColorstr='#efefef', startColorstr='#3399cc', gradientType='0');\"><font face=verdana>".$vraag."</font></td></tr>";
echo "<tr><td STYLE=\"border-style: solid; border-color: #000000;\">";
echo "<table><tr><td bordercolor=#000000 width=11%>";
echo $opties[0] . "</td>";
echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
echo "<td width=$barlengte0 bgcolor=red height=5></td></tr></table></td><td>$pro[0]%</td>";
echo "</tr>";
echo "<tr>";
echo "<td bordercolor=#ffffff width=10%>";
echo $opties[1] . "</td>";
echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
echo "<td width=$barlengte1 bgcolor=red height=5></td></tr></table></td><td>$pro[1]%</td>";
echo "</tr>";
echo "<tr>";
echo "<td bordercolor=#ffffff width=10%>";
echo $opties[2] . "</td>";
echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0 ><tr>";
echo "<td width=$barlengte2 bgcolor=red height=5></td></tr></table></td><td>$pro[2]%</td>";
echo "</tr>";
echo "<tr>";
echo "<td bordercolor=#ffffff width=10%>Gestemd</td>";
}
else
{
Setcookie("gestemd", "ja", Time()+25);
echo "<form method=POST action=poll.php>";
echo "<TABLE border=1 bordercolor=#000000 cellspacing=2 cellpadding=2 STYLE=\"border-style: solid; border-color: #ffffff;\" width=250><TR><TD STYLE=\"border-style: solid; border-color: #000000;\" width=500 colspan=2 style=\"filter:progid:DXImagetransform.Microsoft.Gradient(endColorstr='#efefef', startColorstr='#3399cc', gradientType='0');\"><font face=verdana>".$vraag."</font></td></tr>";
echo "<tr><td STYLE=\"border-style: solid; border-color: #000000;\">";
echo "<table><tr><td bordercolor=#000000 width=11%>";
echo "<input type=radio name=antwoord value=0>".$opties[0]."</td>";
echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
echo "<td width=$barlengte0 bgcolor=red height=5></td></tr></table></td><td>$pro[0]%</td>";
echo "</tr>";
echo "<tr>";
echo "<td bordercolor=#ffffff width=10%>";
echo "<input type=radio name=antwoord value=1>".$opties[1]."</td>";
echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
echo "<td width=$barlengte1 bgcolor=red height=5></td></tr></table></td><td>$pro[1]%</td>";
echo "</tr>";
echo "<tr>";
echo "<td bordercolor=#ffffff width=10%>";
echo "<input type=radio name=antwoord value=2>".$opties[2]."</td>";
echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
echo "<td width=$barlengte2 bgcolor=red height=5></td></tr></table></td><td>$pro[2]%</td>";
echo "</tr>";
echo "<tr>";
echo "<td bordercolor=#ffffff width=10%>";
echo "<input name=submit type=submit value=Stem>";
if(isset($_POST['submit']) && isset($_POST['antwoord']) && empty($HTTP_COOKIE_VARS['gestemd']))
{
$result="result.txt";
$pointer=fopen($result,"r+");
$poll=fread($pointer,filesize($result));
$poll=trim($poll);
$poll=explode(",",$poll);
$poll[$_POST['antwoord']]++;
$poll=$poll[0] . "," . $poll[1] . "," . $poll[2];
rewind($pointer);
fputs($pointer,$poll);
fclose($pointer);
}
}
echo "</form>";
echo "</td><td bordercolor=#ffffff>".$totaal." stemmen</td>";
echo "</tr></td></tr></table></table>";
?>
</body>
</html>
<html> <head> <title>Poll</title> </head> <body> <?php $opties[0] = "<font face=verdana size=2>mooi "; $opties[1] = "<font face=verdana size=2>gaat "; $opties[2] = "<font face=verdana size=2>stom "; $vraag = "<center><font face=verdana size=2>Wat vind je van de poll?</center>"; $result="result.txt"; $pointer=fopen($result,"r"); $totaal=$poll[0]+$poll[1]+$poll[2]; $barlengte=400; $barlengte0=(100/$totaal)*$poll[0]; $barlengte1=(100/$totaal)*$poll[1]; $barlengte2=(100/$totaal)*$poll[2]; $barlengte0=round($barlengte0); $barlengte1=round($barlengte1); $barlengte2=round($barlengte2); $pro[0]=round(100/$totaal*$poll[0]); $pro[1]=round(100/$totaal*$poll[1]); $pro[2]=round(100/$totaal*$poll[2]); { echo "<TABLE border=1 bordercolor=#000000 cellspacing=2 cellpadding=2 STYLE=\"border-style: solid; border-color: #ffffff;\" width=250><TR><TD STYLE=\"border-style: solid; border-color: #000000;\" width=500 colspan=2 style=\"filter:progid:DXImagetransform.Microsoft.Gradient(endColorstr='#efefef', startColorstr='#3399cc', gradientType='0');\"><font face=verdana>".$vraag."</font></td></tr>"; echo "<tr><td STYLE=\"border-style: solid; border-color: #000000;\">"; echo "<table><tr><td bordercolor=#000000 width=11%>"; echo $opties[0] . "</td>"; echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>"; echo "<td width=$barlengte0 bgcolor=red height=5></td></tr></table></td><td>$pro[0]%</td>"; echo "<td bordercolor=#ffffff width=10%>"; echo $opties[1] . "</td>"; echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>"; echo "<td width=$barlengte1 bgcolor=red height=5></td></tr></table></td><td>$pro[1]%</td>"; echo "<td bordercolor=#ffffff width=10%>"; echo $opties[2] . "</td>"; echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0 ><tr>"; echo "<td width=$barlengte2 bgcolor=red height=5></td></tr></table></td><td>$pro[2]%</td>"; echo "<td bordercolor=#ffffff width=10%>Gestemd</td>"; } else { echo "<form method=POST action=poll.php>"; echo "<TABLE border=1 bordercolor=#000000 cellspacing=2 cellpadding=2 STYLE=\"border-style: solid; border-color: #ffffff;\" width=250><TR><TD STYLE=\"border-style: solid; border-color: #000000;\" width=500 colspan=2 style=\"filter:progid:DXImagetransform.Microsoft.Gradient(endColorstr='#efefef', startColorstr='#3399cc', gradientType='0');\"><font face=verdana>".$vraag."</font></td></tr>"; echo "<tr><td STYLE=\"border-style: solid; border-color: #000000;\">"; echo "<table><tr><td bordercolor=#000000 width=11%>"; echo "<input type=radio name=antwoord value=0>".$opties[0]."</td>"; echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>"; echo "<td width=$barlengte0 bgcolor=red height=5></td></tr></table></td><td>$pro[0]%</td>"; echo "<td bordercolor=#ffffff width=10%>"; echo "<input type=radio name=antwoord value=1>".$opties[1]."</td>"; echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>"; echo "<td width=$barlengte1 bgcolor=red height=5></td></tr></table></td><td>$pro[1]%</td>"; echo "<td bordercolor=#ffffff width=10%>"; echo "<input type=radio name=antwoord value=2>".$opties[2]."</td>"; echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>"; echo "<td width=$barlengte2 bgcolor=red height=5></td></tr></table></td><td>$pro[2]%</td>"; echo "<td bordercolor=#ffffff width=10%>"; echo "<input name=submit type=submit value=Stem>"; if(isset($_POST['submit']) && isset($_POST['antwoord']) && empty($HTTP_COOKIE_VARS['gestemd'])) { $result="result.txt"; $pointer=fopen($result,"r+"); $poll[$_POST['antwoord']]++; $poll=$poll[0] . "," . $poll[1] . "," . $poll[2]; } } echo "</td><td bordercolor=#ffffff>".$totaal." stemmen</td>"; echo "</tr></td></tr></table></table>"; ?> </body> </html>
|