Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I run a little script on my server where people can moderate a link (basically up & downvotes). This is run in a CGI::Application I wrote myself, but I'm having a bit of troubles finding a better way to prevent the users from voting multiple times (I don't need top security or anything, I just don't want easy ballotstuffing).

So far, my code looks like this:

sub link_moderate { my $self = shift; my $q = $self->query(); my $output = ""; my $tmpl = $self->load_tmpl('.tmpl'); my $uri = $q->param('uri')||""; my $direction = $q->param('direction')||""; #FIX!! (check for existence of URL) my $statementHandle = $Database->prepare("SELECT COUNT(*) FROM mod +eration WHERE userkey LIKE '".$q->remote_addr."-$uri';"); my $returnValue = $statementHandle->execute; my @results = $statementHandle->fetchrow_array; if ($results[0] >= 1) { $tmpl->param('message' => "Ahem, you've alredy voted at this. +Stop doing it, you won't get any further."); } else { if ($direction eq "up") { my $returnValueStatus = $Database->do("UPDATE saved_search + SET moderation=moderation+1 WHERE uri LIKE '$uri';"); $returnValueStatus = $Database->do("INSERT INTO moderation + VALUES('".$q->remote_addr."-$uri');"); if ($returnValueStatus == 1) { $tmpl->param('message' => "The moderation value for th +e url has been updated."); } else { $tmpl->param('message' => "The URL could not be found +in the database."); } } elsif ($direction eq "down") { my $returnValueStatus = $Database->do("UPDATE saved_search + SET moderation=moderation-1 WHERE uri LIKE '$uri';"); $returnValueStatus = $Database->do("INSERT INTO moderation + VALUES('".$q->remote_addr."-$uri');"); if ($returnValueStatus == 1) { $tmpl->param('message' => "The moderation value for th +e url has been updated."); } else { $tmpl->param('message' => "The URL could not be found +in the database."); } $Database->do("DELETE FROM saved_search WHERE moderation < += -15;"); } else { $tmpl->param('message' => "Eh, what direction would '$dire +ction' be?"); } } $tmpl->param('version' => $VERSION); $tmpl->param('number_of_links' => &get_number_of_links); $tmpl->param('list_urls' => &getlast(10)); $output = clean_html($tmpl->output); $self->header_props(-Content_length=>length($output)); return $output; }

As you can see, there goes an awful lot of data into the moderation table, and it's generally not very pretty.

Any thoughts on this?

Edit kudra, 2002-10-27 Added a readmore tag


In reply to Preventing multiple votes by same user effeciently by carthag

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found