Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
cloud2424
New Member
New Member


Joined: Oct 17, 2005
Posts: 6

PostPosted: Thu Oct 20, 2005 8:43 am Reply with quote

ok one more question raven with the survey block how can i set it up that people are only allowed to vote once. Some reason mine lets them keep voting.
 
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Sat Oct 22, 2005 11:04 am Reply with quote

I have rewritten the code for v6.9. Edit modules/Surveys/index.php. Find function pollCollector($pollID, $voteID, $forwarder) {. Replace with
Code:
function pollCollector($pollID, $voteID, $forwarder) {

   // Reworked by Raven - http://ravenphpscripts.com
   global $HTTP_COOKIE_VARS, $prefix, $db, $index;
   $pollID = intval($pollID);
   $voteID = intval($voteID);
   $past = time()-86400;
   $voteValid = 1;  // Assume Valid
   $ctime = time();
   if (empty($ip)) {
      $ip = $_SERVER["REMOTE_ADDR"];
      if (empty($ip)) $voteValid = 0;
   }
   $sql = "SELECT ip FROM ".$prefix."_poll_check WHERE ip='$ip' AND pollID='$pollID' LIMIT 1";
   $row = $db->sql_query($sql);
   if ($db->sql_numrows($row)) {
      $voteValid=0;
      $sql = "UPDATE ".$prefix."_poll_check set time='$ctime' WHERE ip='$ip' AND pollID='$pollID'";
      $db->sql_query($sql);
   }
   else {
      $sql = "INSERT INTO ".$prefix."_poll_check (ip, time, pollID) VALUES ('$ip', '$ctime', '$pollID')";
      $db->sql_query($sql);
   }
   $db->sql_query("DELETE FROM ".$prefix."_poll_check WHERE time < '$past'");

   /* update database if the vote is valid */
   if ($voteValid==1) {
      $db->sql_query("UPDATE ".$prefix."_poll_data SET optionCount=optionCount+1 WHERE pollID='$pollID' AND voteID='$voteID'");
      if (!empty($voteID)) {
         $sql = "UPDATE ".$prefix."_poll_desc SET voters=voters+1 WHERE pollID='$pollID'";
         $db->sql_query($sql);
      }
   }
   else {
      $index=1;
      include_once('header.php');
      OpenTable();
      echo "<center>Our records show that you have already voted in this poll.<br /><br />This is not Chicago.<br /><br />You may only vote once :lol:</center>";
      CloseTable();
      include_once('footer.php');
      die();
   }
   Header("Location: $forwarder");
   die();
}
 
View user's profile Send private message
JediStryker
Hangin' Around


Joined: Jun 27, 2004
Posts: 38
Location: San Antonio, TX

PostPosted: Fri Mar 17, 2006 10:33 pm Reply with quote

Thanks for this, Raven! Just put it to good use. Your skills are enviable. Wink Smile

_________________
Only registered users can see links on this board! Get registered or login!
A Technician Community/Reference Place 
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Raven
PostPosted: Sat Mar 18, 2006 12:48 am Reply with quote

RavensScripts
 
bugsTHoR
Involved
Involved


Joined: Apr 05, 2006
Posts: 261

PostPosted: Fri Jun 23, 2006 6:52 pm Reply with quote

hi

i would like to know how you set the poll up for the oposite , multiple answers

thx

_________________
Only registered users can see links on this board! Get registered or login! LUV RAVEN DISTROBUTION BEBE

Clanthemes.com are great (free advertisements for now until i get to 20,000 posts LoL) 
View user's profile Send private message Visit poster's website
Raven
PostPosted: Fri Jun 23, 2006 10:25 pm Reply with quote

Multiple answers and multiple voting by the same IP are not the same thing. Are you requesting how to have a user select more than one option at the same time? If so, you have to replace the radio buttons with check boxes and the corresponding logic. Or are you asking how to make it so the same IP could vote 1,000 times for the same answer/question?
 
bugsTHoR
PostPosted: Sat Jun 24, 2006 1:03 am Reply with quote

aahh i see , confusing ,, for me anyways lol
the radio buttons one ,how do i do those with check boxes?? please.
one of the site Admins would like
a poll about all things ...Beer what is your favourite beer/s so that the guys can do more than one ..2 or 3 maybe out 15 beers as our guys are from all over europe so there is lots of beer to chose from.
 
shotokan
Worker
Worker


Joined: Aug 27, 2006
Posts: 172

PostPosted: Wed Oct 04, 2006 3:36 pm Reply with quote

Raven wrote:
Multiple answers and multiple voting by the same IP are not the same thing. Are you requesting how to have a user select more than one option at the same time? If so, you have to replace the radio buttons with check boxes and the corresponding logic. Or are you asking how to make it so the same IP could vote 1,000 times for the same answer/question?


Hey Raven

what about the possibility to make the survey won;t show if the user has voted already? I would like the user now to see the survey anymore if he had voted.
 
View user's profile Send private message
Raven
PostPosted: Wed Oct 04, 2006 9:12 pm Reply with quote

You mean to just show the results?
 
shotokan
PostPosted: Thu Oct 05, 2006 6:48 am Reply with quote

Yes. that's a posibility. What i am really interest is that a particular survey the he had voted already do not show up for him again, this way he wouldn't vote twice.
 
kaine
New Member
New Member


Joined: Dec 12, 2006
Posts: 11

PostPosted: Sat Dec 23, 2006 11:38 am Reply with quote

Hi,

Having the same problem too - I see this post relates to v6.9 and I am using RavenNuke76 v1.x Distro however I tried it anyway - didn't work

Basically I just want to stop multiple votes

Thanks in advance for any help

Kaine
 
View user's profile Send private message
kaine
PostPosted: Sat Dec 30, 2006 6:54 am Reply with quote

sorry to bump this, however I've still not been able to resolve it

Thanks in advance

Kaine
 
kaine
PostPosted: Sat Dec 30, 2006 7:08 am Reply with quote

done - think I was having a blonde moment Rolling Eyes

fyi I wasn't replacing the whole pollCollector section - I just replaced the first line - do'h
 
shotokan
PostPosted: Sat Dec 30, 2006 10:42 am Reply with quote

kaine wrote:
done - think I was having a blonde moment Rolling Eyes

fyi I wasn't replacing the whole pollCollector section - I just replaced the first line - do'h


Sorry to ask but i still have the problem. How did you solve it. My pools stay there for me to vote how many times i want.

The only one that works ok is the one inside the forums but the one on the nuke portal allow people to vote as many times as they want so the voting thing loses its purpose.
 
kaine
PostPosted: Sat Dec 30, 2006 10:48 am Reply with quote

Basically you need to modify the module/surveys/index.php file as per Raven's info

However dont follow the info word for word as I did - you need to find the whole piece of code under pollCollection and replace it with the code Raven provided

That worked for me

Kaine
 
shotokan
PostPosted: Sat Dec 30, 2006 12:28 pm Reply with quote

Raven wrote:
I have rewritten the code for v6.9. Edit modules/Surveys/index.php. Find function pollCollector($pollID, $voteID, $forwarder) {. Replace with
Code:
function pollCollector($pollID, $voteID, $forwarder) {

   // Reworked by Raven - http://ravenphpscripts.com
   global $HTTP_COOKIE_VARS, $prefix, $db, $index;
   $pollID = intval($pollID);
   $voteID = intval($voteID);
   $past = time()-86400;
   $voteValid = 1;  // Assume Valid
   $ctime = time();
   if (empty($ip)) {
      $ip = $_SERVER["REMOTE_ADDR"];
      if (empty($ip)) $voteValid = 0;
   }
   $sql = "SELECT ip FROM ".$prefix."_poll_check WHERE ip='$ip' AND pollID='$pollID' LIMIT 1";
   $row = $db->sql_query($sql);
   if ($db->sql_numrows($row)) {
      $voteValid=0;
      $sql = "UPDATE ".$prefix."_poll_check set time='$ctime' WHERE ip='$ip' AND pollID='$pollID'";
      $db->sql_query($sql);
   }
   else {
      $sql = "INSERT INTO ".$prefix."_poll_check (ip, time, pollID) VALUES ('$ip', '$ctime', '$pollID')";
      $db->sql_query($sql);
   }
   $db->sql_query("DELETE FROM ".$prefix."_poll_check WHERE time < '$past'");

   /* update database if the vote is valid */
   if ($voteValid==1) {
      $db->sql_query("UPDATE ".$prefix."_poll_data SET optionCount=optionCount+1 WHERE pollID='$pollID' AND voteID='$voteID'");
      if (!empty($voteID)) {
         $sql = "UPDATE ".$prefix."_poll_desc SET voters=voters+1 WHERE pollID='$pollID'";
         $db->sql_query($sql);
      }
   }
   else {
      $index=1;
      include_once('header.php');
      OpenTable();
      echo "<center>Our records show that you have already voted in this poll.<br /><br />This is not Chicago.<br /><br />You may only vote once :lol:</center>";
      CloseTable();
      include_once('footer.php');
      die();
   }
   Header("Location: $forwarder");
   die();
}


I have a phpnuke 7.8 patched 3.2b would that solution work for me too? Asking because my function pollCollector looks different.

Mine is like that
function pollCollector($pollID, $voteID)

and Ravens is like that
function pollCollector($pollID, $voteID, $forwarder)
 
kaine
PostPosted: Sat Dec 30, 2006 12:50 pm Reply with quote

$forwarder just returns the voter to the results page once voted (I think), so shouldn't be a problem

can you test it on a local server first? just make sure you back up the original index.php and test it

Kaine
 
warren-the-ape
Worker
Worker


Joined: Nov 19, 2007
Posts: 196
Location: Netherlands

PostPosted: Sat Dec 29, 2007 10:57 am Reply with quote

Many thnx for this fix Raven Cool 1 of those little annoying nuke thingies that was making the surveys/polls quite useless to use (in a 'legal' way).

But i did notice that the code in ravennuke 2.10.01 looks almost the same as my original one (php-nuke 7.9), and looks nothing like the fix you provided above.

Anyway i hope there arent any security holes in it?


I also needed to rewrite it a bit to make it work in PHP-Nuke 7.9 (patched 3.3)

Code:


function pollCollector($pollID, $voteID) {
   // Reworked by Raven - http://ravenphpscripts.com
   global $HTTP_COOKIE_VARS, $prefix, $db, $index, $module_name;
   $pollID = intval($pollID);
   $voteID = intval($voteID);
   $past = time()-86400;
   $voteValid = 1;  // Assume Valid
   $ctime = time();
   if (empty($ip)) {
      $ip = $_SERVER["REMOTE_ADDR"];
      if (empty($ip)) $voteValid = 0;
   }
   $sql = "SELECT ip FROM ".$prefix."_poll_check WHERE ip='$ip' AND pollID='$pollID' LIMIT 1";
   $row = $db->sql_query($sql);
   if ($db->sql_numrows($row)) {
      $voteValid=0;
      $sql = "UPDATE ".$prefix."_poll_check set time='$ctime' WHERE ip='$ip' AND pollID='$pollID'";
      $db->sql_query($sql);
   }
   else {
      $sql = "INSERT INTO ".$prefix."_poll_check (ip, time, pollID) VALUES ('$ip', '$ctime', '$pollID')";
      $db->sql_query($sql);
   }
   $db->sql_query("DELETE FROM ".$prefix."_poll_check WHERE time < '$past'");

   /* update database if the vote is valid */
   if ($voteValid==1) {
      $db->sql_query("UPDATE ".$prefix."_poll_data SET optionCount=optionCount+1 WHERE pollID='$pollID' AND voteID='$voteID'");
      if (!empty($voteID)) {
         $sql = "UPDATE ".$prefix."_poll_desc SET voters=voters+1 WHERE pollID='$pollID'";
         $db->sql_query($sql);
      }
   }
   else {
      $index=1;
      include_once('header.php');
      OpenTable();
      echo "<center>Our records show that you have already voted in this poll.<br /><br />You may only vote once!<br /><br />[ <a href=\"/\">Go Back</a> | <a href=\"modules.php?name=$module_name&op=results&pollID=$pollID\">Poll Results</a> ]</center>";
      CloseTable();
      include_once('footer.php');
      die();
   }
   Header("Location: modules.php?name=$module_name&op=results&pollID=$pollID");
   die();
}


Added $module_name (since i dont have that $forwarder) to make the redirect link to the results work.
Hope i did it correct Very Happy
 
View user's profile Send private message
warren-the-ape
PostPosted: Fri Jan 11, 2008 6:27 am Reply with quote

After running this modification for 2 weeks now i noticed that after some time i was still able to vote again. At first i thought it was cause of the year change but later experienced the same thing after a couple of days.


I wondered if it has anything to do with this line (?);
Code:
$past = time()-86400;


If so, could i just enter a higher number?
 
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Fri Jan 11, 2008 12:09 pm Reply with quote

86400 is the number of seconds in one day. Changing the number higher should create a longer cookie, which could last for longer than a day. (Of course, if users clear their cookies, they can bypass this step rather easily)

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
warren-the-ape
PostPosted: Fri Jan 11, 2008 12:47 pm Reply with quote

Aah okay I see now, so the votes are based on the user's cookie?
But that would mean its not completely watertight.

I guess it would need quite some re-coding to make a vote from a user really permanent?
 
evaders99
PostPosted: Fri Jan 11, 2008 1:44 pm Reply with quote

Yes - there really is no watertight solution. The best you could do is some kind of 'smart' consolidation with cookies, IP address, maybe browser User-agent or making it require a Nuke user login. Checking an online identity is a problem throughout the web
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©