Web Hosting Talk







View Full Version : php cookie wont set


latheesan
07-26-2006, 05:33 PM
Hello,

This is a small snippet of my poll voting script:

if($_GET["act"] == "vote")
{
$poll_id = $_POST["poll_id"] ? $_POST["poll_id"] : '';
$poll_option = $_POST["option"] ? $_POST["option"] : '';
if($_COOKIE["poll_voted"] == "yes" && $_COOKIE["poll_voted_id"] == $poll_id)
{
$error .= '<font color="#cc0000">Sorry, you can vote only once per hour, per poll!</font><br>';
}
else
{
include("inc/mysql.php");
$query = "SELECT * FROM poll_questions WHERE id = '". mysql_real_escape_string($poll_id) ."' LIMIT 1";
$result = mysql_query($query);
$num = mysql_num_rows($result);
if($num >= 1)
{
setcookie("poll_voted", "yes", time()+3600);
setcookie("poll_voted_id", $poll_id, time()+3600);
$query2 = "UPDATE `poll_options` SET `votes` = `votes` + 1 WHERE `option` = '". $poll_option ."' AND `poll_id` = ". $poll_id ."";
mysql_query($query2);
mysql_close();
$success .= '<font color="#009D00">Thanks, you have successfully voted for this poll and your vote has been accepted</font>';
}
else
{
mysql_close();
$error .= '<font color="#cc0000">Sorry, you have specified an invalid Poll ID</font><br>';
}
}
}

Cookie isnt getting set, thus, the user can vote unlimited times... can u help plz, duno where i went wrong...

Arrbz
07-26-2006, 06:42 PM
I Dont Know nothing about PHP, so I cant say if anything wrong with the code, but... if the browser is set to block cookies theres nothing you can do.

In my poll codings I chequed both cookies and IP, and still some users find ways to vote again (rotatible IPs, anom proxyes, etc).

The only way to really prevent multiples votes is with registered and verified users.

latheesan
07-26-2006, 06:57 PM
hey Arrbz, thanks for your reply.

My browser is set to accept normal and session cookies, so there is no problem with that. As for the multiple voting issue, im not really bothered about it that much, thats why im using cookie method to stop them. I just wish i know whats wrong...

latheesan
07-26-2006, 07:31 PM
Okay, nvm, i got it to work thuru using mysql database and user's ip...

does anyone know how i can represent the votes as a nice bar chart?

e.g.

Poll Question
What do you think of my site?

Poll Options | Votes
Very Nice | 23
Not Bad | 12
Bad | 2
Very Bad | 0

Now how can i represent the votes as a bar chart? not like a proper graph made in GD, i mean, a simple graph. Just a bit confused about workout out the averages etc...

horizon
07-26-2006, 07:50 PM
Now how can i represent the votes as a bar chart? not like a proper graph made in GD, i mean, a simple graph. Just a bit confused about workout out the averages etc...


Since you have decided to calculate your results from your mySQL database, did you set the summary calculation, under one of your SQL statement, in order to show the total votes results ?

El-Vino
07-27-2006, 12:43 AM
Okay, nvm, i got it to work thuru using mysql database and user's ip...

does anyone know how i can represent the votes as a nice bar chart?

e.g.

Poll Question
What do you think of my site?

Poll Options | Votes
Very Nice | 23
Not Bad | 12
Bad | 2
Very Bad | 0

Now how can i represent the votes as a bar chart? not like a proper graph made in GD, i mean, a simple graph. Just a bit confused about workout out the averages etc...

Well, the most simple (and that might not qualify as "nice" bar chart) way it to use a one pixel color image and strech it to the number of votes (or percentage), like <img src="one_of_the_color.gif" height="10" width="<? echo $someResult; ?>" />

that is very rough, but you get the idea.

latheesan
08-05-2006, 11:58 AM
yea, thanks for that ^^;

horizon
08-05-2006, 01:24 PM
Well, the most simple (and that might not qualify as "nice" bar chart) way it to use a one pixel color image and strech it to the number of votes (or percentage), like <img src="one_of_the_color.gif" height="10" width="<? echo $someResult; ?>" />


Althought, I don't think this technic would work with decimals, by using width with <img src, it would actually work with non-decimals value I believe.