php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch prevent-users-from-voting-multiple-times-on-same-bug for Website problem Bug #51535

Patch version 2014-12-31 11:25 UTC

Return to Bug #51535 | Download this patch
Patch Revisions:

Developer: jacob.bednarz@gmail.com

From 90b07aee49ea4227c82f80a0136e21695126633b Mon Sep 17 00:00:00 2001
From: Jacob Bednarz <jacob.bednarz@gmail.com>
Date: Wed, 31 Dec 2014 07:41:55 +1000
Subject: [PATCH] Prevent users from adding multiple votes on a single bug

---
 www/bug.php  |  3 +++
 www/vote.php | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/www/bug.php b/www/bug.php
index d8f8398..4f73455 100644
--- a/www/bug.php
+++ b/www/bug.php
@@ -601,6 +601,9 @@ switch ($thanks)
 	case 9:
 		display_bug_success('You have successfully unsubscribed.');
 		break;
+	case 10:
+		display_bug_success('You have already voted on this bug.');
+	break;
 
 	default:
 		break;
diff --git a/www/vote.php b/www/vote.php
index 12d2ac5..536ff55 100644
--- a/www/vote.php
+++ b/www/vote.php
@@ -55,6 +55,16 @@ function get_real_ip ()
 $ip = ip2long(get_real_ip());
 // TODO: check if ip address has been banned. hopefully this will never need to be implemented.
 
+// Check whether the user has already voted on this bug.
+$bug_check = $dbh->prepare("SELECT bug, ip FROM bugdb_votes WHERE bug = ? AND ip = ? LIMIT 1")
+	->execute(array($id, $ip))
+	->fetchRow();
+
+if (!empty($bug_check)) {
+	// Let the user know they have already voted.
+	redirect("bug.php?id=$id&thanks=10");
+}
+
 // add the vote
 $dbh->prepare("
 	INSERT INTO bugdb_votes (bug,ip,score,reproduced,tried,sameos,samever)
-- 
2.2.1

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 06:01:30 2024 UTC