Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: One Vote per IP

  1. #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>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 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:

    Hydrian (09-23-2012)

  • #3
    New Coder
    Join Date
    Aug 2012
    Posts
    40
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 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.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,627
    Thanks
    0
    Thanked 648 Times in 638 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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Last edited by Philip M; 09-24-2012 at 07:55 AM.

    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.

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 584 Times in 565 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...
    Last edited by rnd me; 09-24-2012 at 10:44 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •