Het onderstaande script werkt wel, maar de COOKIE wordt NIET geplaats. Als ik de function header en footer weg haal werkt het wel. Hoe kan ik dit oplossen? Ik weet dat de setcookie helemaal aan het begin moet, maar hoe krijg ik deze daar?
<?php
// versie 25 oktober 2006
// Error rapporting E_ALL voor in de testfase ,daarna op 0 zetten voor online productie
error_reporting(E_ALL);
// error_reporting(0);
// Hier de default html opmaak/kop voor alle pagina's
function enquete_head()
{
header("Expires: Sun, 11 Apr 1999 08:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: pre-check=0, post-check=0", FALSE);
header("Pragma: no-cache");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>mini_onderzoek</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 12px;
font-color: black;
background-color:#66FFCC;
margin-top: 15px;
}
input {
font-family: Arial, sans-serif;
font-size: 12px;
width: 300px;
}
.inputsmall {
font-family: Arial, sans-serif;
font-size: 12px;
width: 160px;
}
select {
font-family: Arial, sans-serif;
font-size: 12px;
width: 310px;
}
textarea {
font-family: Arial, sans-serif;
font-size: 12px;
width: 310px;
height: 60px;
}
.style1 {color: #770000}
</style>
</head>
<body>
<?php
// dit is de uitlog knop via logout.php gaat die gewoon weer naar de start van de webpage
echo "
<form action='logout.php' method='post'>
<input type='submit' name='submit' value='Dit scherm sluiten' class='inputsmall' > </form>";
?>
<table border=0 width=650>
<tr>
<td valign="top" width=50>
</td>
<td width="650" valign="top">
<?php
}
function enquete_foot()
{
?>
</td>
</tr>
</table>
<!-- <?php echo "door CM, basis v/h script is uit boek van S.Terryn " . date("Y") . " groetjes..."; ?> -->
</body>
</html>
<?php
}
// Einde default html opmaak/kop voor alle pagina's
//*******************************************************
// Hier begint het script
function vragen_mini_onderzoek ($submit="", $antwoord="", $gestemd="")
{
$submit=$_POST["submit"];
$antwoord=$_POST["antwoord"];
$gestemd=$HTTP_COOKIE_VARS["gestemd"];
if (isset($submit)) { setcookie("gestemd","ja",time()+60); }
echo "<h2> Mini onderzoek, doe mee !</h2>\n";
echo "<h3><i> Vraag: Dit soort enquetes zijn erg stom. </i></h3>\n";
echo "<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">\n";
// dit is de tabel met de knopjes
echo "<table width=\"500\"
border=\"0\"
cellpadding=\"0\"
align=\"left\"
bgColor=\"\">";
echo "<tr>";
echo "<td width=\"200\" align=\"left\" valign=\"middle\">";
echo "Mee eens";
echo "</td>";
echo "<td width=\"200\" align=\"left\" valign=\"middle\">";
echo "<input type=\"radio\" name=\"antwoord\" value=\"0\">\n";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"200\" align=\"left\" valign=\"middle\">";
echo "Mee oneens";
echo "</td>";
echo "<td width=\"200\" align=\"left\" valign=\"middle\">";
echo "<input type=\"radio\" name=\"antwoord\" value=\"1\">\n";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"200\" align=\"left\" valign=\"middle\">";
echo "Geen mening";
echo "</td>";
echo "<td width=\"200\" align=\"left\" valign=\"middle\">";
echo "<input type=\"radio\" name=\"antwoord\" value=\"2\">\n";
echo "</td>";
echo "</tr>";
echo "</table><br>";
echo "<p> </p>";// einde van de tabel
echo "<br><br>\n";
if (empty($submit) && empty($gestemd) && empty($HTTP_COOKIE_VARS["gestemd"])) {
echo "<input name=\"submit\" type=\"submit\" value=\"Stem uitbrengen\" class='inputsmall' \n";
echo "<br>";
} else {
echo "<font color=\"#FF0000\" size=\"+1\">Bedankt voor je stem !</font><br><br>";
if (isset($submit) && isset($antwoord) && empty($HTTP_COOKIE_VARS["gestemd"]))
{
$result="mini_onderzoek_result.txt";
$pointer=fopen($result,"r+");
$peiling=fread($pointer,filesize($result));
$peiling=trim($peiling);
$peiling=explode(",",$peiling);
$peiling[$_POST["antwoord"]]++;
$peiling=$peiling[0] . "," . $peiling[1] . "," . $peiling[2];
rewind($pointer);
fputs($pointer,$peiling);
fclose($pointer);
echo "</form> <br>";
echo "<p>[ <a href=\"mini_onderzoek_uitslag.php\">Bekijk de resultaten van de peiling</a>]</p><br>\n"; // test knop kan later weg
// dit is de info knop mbt de uitslag van het mini onderzoek
echo "<form action=\"mini_onderzoek_uitslag.php\" method=\"post\">\n";
echo "<input name=\"submit\" type=\"submit\" value=\"Uitslag mini onderzoek\" class='inputsmall' \n";
echo "</form> <br>";
}
}
}
// Genereer nu de header voor de paginas
enquete_head();
vragen_mini_onderzoek ();
// Genereer nu de footer voor de paginas
enquete_foot();
?>
1.228 views