Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-23-2012, 10:04 AM   PM User | #1
Hydrian
New Coder

 
Join Date: Aug 2012
Posts: 40
Thanks: 5
Thanked 0 Times in 0 Posts
Hydrian is an unknown quantity at this point
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>
Hydrian is offline   Reply With Quote
Old 09-23-2012, 10:41 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
Hydrian (09-23-2012)
Old 09-23-2012, 10:45 AM   PM User | #3
Hydrian
New Coder

 
Join Date: Aug 2012
Posts: 40
Thanks: 5
Thanked 0 Times in 0 Posts
Hydrian is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
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?
Hydrian is offline   Reply With Quote
Old 09-23-2012, 10:52 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Hydrian View Post
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.
Philip M is offline   Reply With Quote
Old 09-23-2012, 10:35 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-23-2012, 10:41 PM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 09-24-2012, 07:46 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Have a look at

http://www.technabled.com/2011/02/pu...wn-voting.html

http://www.freepolls.com/
__________________

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..
Philip M is offline   Reply With Quote
Old 09-24-2012, 10:42 AM   PM User | #8
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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..
rnd me is offline   Reply With Quote
Old 09-24-2012, 11:37 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:41 PM.


Advertisement
Log in to turn off these ads.