login  Naam:   Wachtwoord: 
Registreer je!
 Forum

cookie werkt niet

Offline remy - 09/09/2004 16:04
Avatar van remyPHP 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.:

  1. <html>
  2. <head>
  3.  
  4. <title>Poll</title>
  5. </head>
  6. <body>
  7.  
  8. <?php
  9. $opties[0] = "<font face=verdana size=2>mooi ";
  10. $opties[1] = "<font face=verdana size=2>gaat ";
  11. $opties[2] = "<font face=verdana size=2>stom ";
  12. $vraag = "<center><font face=verdana size=2>Wat vind je van de poll?</center>";
  13.  
  14. $result="result.txt";
  15. $pointer=fopen($result,"r");
  16. $poll=fread($pointer,filesize($result));
  17. fclose($pointer);
  18. $poll=explode(",",$poll);
  19.  
  20. $totaal=$poll[0]+$poll[1]+$poll[2];
  21.  
  22. $barlengte=400;
  23. $barlengte0=(100/$totaal)*$poll[0];
  24. $barlengte1=(100/$totaal)*$poll[1];
  25. $barlengte2=(100/$totaal)*$poll[2];
  26. $barlengte0=round($barlengte0);
  27. $barlengte1=round($barlengte1);
  28. $barlengte2=round($barlengte2);
  29.  
  30. $pro[0]=round(100/$totaal*$poll[0]);
  31. $pro[1]=round(100/$totaal*$poll[1]);
  32. $pro[2]=round(100/$totaal*$poll[2]);
  33.  
  34. if(isset($gestemd))
  35. {
  36. 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>";
  37. echo "<tr><td STYLE=\"border-style: solid; border-color: #000000;\">";
  38. echo "<table><tr><td bordercolor=#000000 width=11%>";
  39. echo $opties[0] . "</td>";
  40. echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
  41. echo "<td width=$barlengte0 bgcolor=red height=5></td></tr></table></td><td>$pro[0]%</td>";
  42. echo "</tr>";
  43. echo "<tr>";
  44. echo "<td bordercolor=#ffffff width=10%>";
  45. echo $opties[1] . "</td>";
  46. echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
  47. echo "<td width=$barlengte1 bgcolor=red height=5></td></tr></table></td><td>$pro[1]%</td>";
  48. echo "</tr>";
  49. echo "<tr>";
  50. echo "<td bordercolor=#ffffff width=10%>";
  51. echo $opties[2] . "</td>";
  52. echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0 ><tr>";
  53. echo "<td width=$barlengte2 bgcolor=red height=5></td></tr></table></td><td>$pro[2]%</td>";
  54. echo "</tr>";
  55. echo "<tr>";
  56. echo "<td bordercolor=#ffffff width=10%>Gestemd</td>";
  57. }
  58. else
  59. {
  60. Setcookie("gestemd", "ja", Time()+25);
  61. echo "<form method=POST action=poll.php>";
  62. 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>";
  63. echo "<tr><td STYLE=\"border-style: solid; border-color: #000000;\">";
  64. echo "<table><tr><td bordercolor=#000000 width=11%>";
  65. echo "<input type=radio name=antwoord value=0>".$opties[0]."</td>";
  66. echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
  67. echo "<td width=$barlengte0 bgcolor=red height=5></td></tr></table></td><td>$pro[0]%</td>";
  68. echo "</tr>";
  69. echo "<tr>";
  70. echo "<td bordercolor=#ffffff width=10%>";
  71. echo "<input type=radio name=antwoord value=1>".$opties[1]."</td>";
  72. echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
  73. echo "<td width=$barlengte1 bgcolor=red height=5></td></tr></table></td><td>$pro[1]%</td>";
  74. echo "</tr>";
  75. echo "<tr>";
  76. echo "<td bordercolor=#ffffff width=10%>";
  77. echo "<input type=radio name=antwoord value=2>".$opties[2]."</td>";
  78. echo "<td bordercolor=#ffffff><table border=0 cellspacing=0 cellpadding=0><tr>";
  79. echo "<td width=$barlengte2 bgcolor=red height=5></td></tr></table></td><td>$pro[2]%</td>";
  80. echo "</tr>";
  81. echo "<tr>";
  82. echo "<td bordercolor=#ffffff width=10%>";
  83. echo "<input name=submit type=submit value=Stem>";
  84.  
  85. if(isset($_POST['submit']) && isset($_POST['antwoord']) && empty($HTTP_COOKIE_VARS['gestemd']))
  86. {
  87.  
  88. $result="result.txt";
  89. $pointer=fopen($result,"r+");
  90. $poll=fread($pointer,filesize($result));
  91. $poll=trim($poll);
  92. $poll=explode(",",$poll);
  93. $poll[$_POST['antwoord']]++;
  94. $poll=$poll[0] . "," . $poll[1] . "," . $poll[2];
  95. rewind($pointer);
  96. fputs($pointer,$poll);
  97. fclose($pointer);
  98.  
  99.  
  100.  
  101. }
  102.  
  103. }
  104.  
  105.  
  106.  
  107.  
  108. echo "</form>";
  109. echo "</td><td bordercolor=#ffffff>".$totaal." stemmen</td>";
  110. echo "</tr></td></tr></table></table>";
  111. ?>
  112. </body>
  113. </html>

5 antwoorden

Gesponsorde links
Offline Tuinstoel - 09/09/2004 16:38
Avatar van Tuinstoel PHP expert Setcookie("gestemd", "ja", Time()+25);

voor maar 25 seconden? http://www.php.net/setcookie voor wat meer informatie erover.

  1. <?
  2. setcookie("gestemd","ja",time()+3600*24*7); // zet een cookie voor een week
  3. ?>

Offline xSc - 09/09/2004 16:48
Avatar van xSc Onbekend Heej, ga ook een gebruik maken van SuperGlobals, tenzij je gebruik maakt van een prehistorische php-versie .
Offline remy - 09/09/2004 16:53
Avatar van remy PHP ver gevorderde superglobal? hoe bedoel je dat?
Offline Dennisvb - 09/09/2004 16:53
Avatar van Dennisvb MySQL ver gevorderde $vraag = $_POST['vraag'] enz
Offline Tuinstoel - 09/09/2004 17:38
Avatar van Tuinstoel PHP expert http://www.site...&id=65 voor wat meer informatie over superglobals.
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.2s