Enjoy an ad free experience by logging in. Not a member yet?
Register .
09-23-2012, 10:04 AM
PM User |
#1
New Coder
Join Date: Aug 2012
Posts: 40
Thanks: 5
Thanked 0 Times in 0 Posts
One Vote per IP
I have a application where users can vote for submission, and i want to make sure users dont spam it, how can i make this one vote per IP?
Code:
<script type="text/javascript">
var clicks2 = 0;
function linkClick2()
{
document.getElementById('clicked2').value = ++clicks2;
}
document.write('<a href="#" onclick="linkClick2()" class="vote_link">Vote for this Submission</a>');
</script>
09-23-2012, 10:41 AM
PM User |
#2
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
You cannot do that with Javascript. You must use server-side coding.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Users who have thanked Philip M for this post:
09-23-2012, 10:45 AM
PM User |
#3
New Coder
Join Date: Aug 2012
Posts: 40
Thanks: 5
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
Philip M
You cannot do that with Javascript. You must use server-side coding.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
how would i go about doing that tho?
09-23-2012, 10:52 AM
PM User |
#4
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Quote:
Originally Posted by
Hydrian
how would i go about doing that tho?
Ask in the PHP forum. You will need to keep a database of IP addresses that have voted.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
09-23-2012, 10:35 PM
PM User |
#5
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Or ASP forum or Java forum...depending on what kind of server-side language you want to use.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
09-23-2012, 10:41 PM
PM User |
#6
Master Coder
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
It isn't exactly going to be fair though - where 1000 people are sharing the same IP only the first of them to vote will have their vote accepted while someone else whose IP address changes regularly will still be able to cast multiple votes.
Of course that may not matter depending on the requirements.
09-24-2012, 07:46 AM
PM User |
#7
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Last edited by Philip M; 09-24-2012 at 07:55 AM ..
09-24-2012, 10:42 AM
PM User |
#8
Senior Coder
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
use the ip as the primary key of a 2-col poll table.
the vote is an integer 0-5 or whatever.
Code:
IP VOTE
1.1.1.1 4
1.2.1.1 2
1.2.1.1 2
4.2.1.1 0
1.2.9.1 3
i use zero here to 'cancel' a vote for a given ip. looks like #2 is winning...
in this way, someone can update their vote, but they can't vote more times than you can reasonably screen against without sign-in.
yes, they can vote at the coffee shop, on their phone, and at work, but they can't sit there and vote 500 times in a row...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8%
IE10:10%
Last edited by rnd me; 09-24-2012 at 10:44 AM ..
09-24-2012, 11:37 PM
PM User |
#9
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
But Felgall's point needs to be considered as well: Many people use large-scale ISPs or are on machines behind a company firewall. In such cases, you can have hundreds or even thousands of users (e.g., Microsoft has only a handful of outward facing IP addresses for all its thousands of emploeyees) with the same IP address. So if one person using that ISP or from that company votes, nobody else will be able to.
Now, maybe you don't care about these people, and that's really fine. Just be aware that the problem exists.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 08:07 PM .
Advertisement
Log in to turn off these ads.