I can’t understand what wrong with my cookies & poll. The problem is that I can vote as many times I want to. And when the cookie has been sat and I reopen the page then it acts like there is no cookie at all. I’m most grateful if you can solve this problem or give something to work with. I mange to deal with cookies on a different folder (a background changer) so I believe it inst something wrong with my server.
Thanks for your time.
knuff
Here is my script:
<?php
$conn = mysql_connect("localhost","root","root");
mysql_select_db("poll")or die ("Couldn't connect to Database !");
if(!isset($_REQUEST["pollcookie"]))
{
if (!isset($HTTP_COOKIE_VARS['pollcookie']))
{
$rostat="nej";
setcookie("pollcookie", $rostat, time()+3600*1000, "http://localhost/mysqltestar/");
}
}
else
{
$rostat = "ja";
}
if($radiopoll==1)
{
$poll_checked_1 = "checked";
if (!isset($HTTP_COOKIE_VARS['pollcookie']))
{
mysql_query("UPDATE polli SET ja=ja+1");
$rostat="ja";
setcookie("pollcookie", $rostat, time()+3600*1000, "http://localhost/mysqltestar/");
}
}
if($radiopoll==2)
{
$poll_checked_2 = "checked";
if (!isset($HTTP_COOKIE_VARS['pollcookie']))
{
mysql_query("UPDATE polli SET nej=nej+1");
$rostat="ja";
setcookie("pollcookie", $rostat, time()+3600*1000, "http://localhost/mysqltestar/");
}
}
?>
<html>
<head>
<title>phppollomatic</title>
</head>
<body>
<form name="radiopollform" action="<?php $_SERVER[PHP_SELF] ?>" method="post">
<input type="radio" class="Button" value="1" name="radiopoll" onclick="document.radiopollform.submit()" <?php echo ''.$poll_checked_1.'' ?>>
<input type="radio" class="Button" value="2" name="radiopoll" onclick="document.radiopollform.submit()" <?php echo ''.$poll_checked_2.'' ?>>
</form>
<?php
$result = mysql_query("SELECT * FROM polli");
while ($hamta = mysql_fetch_array($result))
{
$total = ($hamta["nej"] + $hamta["ja"]);
$gron = (($hamta["ja"] / $total)*100);
$rod = (($hamta["nej"] / $total)*100);
echo ' rostat is now '.$rostat.'
<table width="380" class="brodtext" border="1">
<tr>
<td width="18" valign="bottom"><img src="top_bar.gif"><br><img src="gron_bar.gif" width="5" height="'.$gron.'"><br>ja:'.$hamta["ja"].'</d>
<td width="18" valign="bottom"><img src="top_bar.gif"><br><img src="rod_bar.gif" width="5" height="'.$rod.'"><br>nej:'.$hamta["nej"].'</td>
</table>
';
}
?>
</body>
</html>