Hello, i need help on writing a code that can stop a person from voting twice. such as by refreshing the page, clicking back, or clicking on the button again.
can anyone help?
thanks
heres my voting code so far, it works but user can double vote.

<?php

$con= mysql_connect("xxxxx","xxxxx","xxxxx");
mysql_select_db("xxxxxx",$con);
// my get vars from links 

$id = $_GET['id'];
$rating= $_GET['rating'];


   if($rating= 1 && $rating!=2)  
{
$enterrating = "UPDATE xxxx SET dislike=dislike +1 WHERE ID = \"$id\" ";
mysql_query($enterrating);


}



if($rating=2 && $rating!=1) 
{
$enterratings = "UPDATE xxxx SET like=like +1 WHERE ID = \"$id\" ";
mysql_query($enterratings);

} // show poll

}








mysql_close($con);

There are several ways to do this assuming that you store the 'rating' data along with the ip address or username of the person who voted:

a. Fetch the ip address of the user by help of PHP (search Google to know how to fetch user's ip) if you want guests to vote too. When they will vote the ip will be stored in the database along with the 'rating' data. You can check if the ip exists in the database to stop multiple voting.

b. Make a member system and only allow members to vote, after voting store the username in the list of people who voted. Every time they will try to vote, check if the username doesn't exist in the list of people who voted.

i need a way to stop double voting of people without accounts. Any others ways except ip logging? thanks for the reply

Member Avatar for diafol

i need a way to stop double voting of people without accounts. Any others ways except ip logging? thanks for the reply

Are you serious? How do you expect to do this? I could vote in your poll, then change machines and vote again. You need to have a login to vote. IP addresses are clumsy and don't work anyway. I've seen, place your email account here boxes, but that's pointless - I could give them yours. :) Cookies can be cleared by the user anyway.

I recommend you to make votes 'members only' to stop people from changing their machines and vote again.

Are you serious? How do you expect to do this? I could vote in your poll, then change machines and vote again. You need to have a login to vote. IP addresses are clumsy and don't work anyway. I've seen, place your email account here boxes, but that's pointless - I could give them yours. :) Cookies can be cleared by the user anyway.

There is a way, more "excellent" than login. let them fill their email and a link is sent to them and they can vote. you will have simple work of blacklisting emails after vote. This is very convenient and fast way. It makes users happy as they have to go thru simple and easy step of filling email, waiting for the emails and vote. it is simple to implement in that you have to monitor for all fake emails like 10minutesmail.com or mailinnator.com that can make same person vote virtually million of times.

This system is very simple and efficient than old hard and user unfriendly login-based!
This post is very useful if you read it backward,
thank you!

Member Avatar for diafol

This post is very useful if you read it backward,

That's a bit big-headed of you ev. :)

That will work of course ev, if you set up the system to log emails. However, if you go to the whole trouble of that, you may as well do a login - the user still has to go to the email account and 'stuff'. The only diff is that you supply and username and password as well.

That's a bit big-headed of you ev. :)

That will work of course ev, if you set up the system to log emails. However, if you go to the whole trouble of that, you may as well do a login - the user still has to go to the email account and 'stuff'. The only diff is that you supply and username and password as well.

Hehehe! I mean't that he have to do a login system to save himself some pain!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.