1. die vote.php
Code: Alles auswählen
<?php
define("IN_EasyHP", true);
session_start();
if (!isset($_SESSION['captcha']) AND $_COOKIE['captcha_set'] != 'TRUE') {
header("Location: captcha.php?link=vote.php");
}
include "includes/mysql.php";
include "common.php";
include "includes/website.php";
$file = "votes.txt"; // Name of the file which
// contains the number of
// votes
$title = "Was für Musik hört ihr?"; // Title
// of
// the
// poll
$answers = array("Rock!", // Possible
"HipHop", // answers
"Pop",
"Andere");
?>
<h3><?php echo $title; ?></h3>
<p>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<?php
//print possible answers
for($i=0;$i<count($answers);$i++){
?><input type="radio" name="vote" value="<?php echo $i; ?>"> <?php echo $answers[$i]; ?><br /><?php
}
?>
<p><input type="submit" value="Vote!"></p>
</form>
</p>
<h3>Ergebnis</h3>
<p>
<?php
//read votes
$votes = file($file);
$total = 0;
$vote = $_POST["vote"];
//submit vote
if(isset($vote)){
$votes[$vote] = $votes[$vote]+1;
}
//write votes
$handle = fopen($file,"w");
foreach($votes as $v){
$total += $v;
fputs($handle,chop($v)."\n");
}
fclose($handle);
//print votes
for($i=0;$i<count($answers);$i++){
echo "{$votes[$i]} {$answers[$i]}<br />";
}
?>
</p>
<p>Gesamt: <?php echo $total; ?> Stimme(n).</p>
<?php
footer(0);
?>
Code: Alles auswählen
0
0
0
0