Jump to content
shawnadelic

Question implementing poll (limiting number of votes by each IP address?)

Recommended Posts

Hi, I'm working on implementing a poll system with a variable number of choices that a user can vote form (via a submission form). Currently, each poll question is stored as a page with each choice being a child of the Poll page (as seen below). Additionally, each choice has a "votes" field which tracks the number of votes a particular choice gets.

--Poll

----Choice 1

----Choice 2

----Choice 3

However, I'm unsure how to limit the number of times a user can vote on a particular poll. Ideally, I would like to allow a user to vote once a day (every 24 hours), so I'm assuming I would have to do this by logging the user's IP address each time a vote is cast. I'm assuming that this would need to be done automatically by the voting function and I would need to track this by adding a "Vote Tracker" child page or something similiar and adding child votes to it each time that would include an IP address and the date/time it was cast, however this seems a bit cumbersome, especially as I would need to make sure there was a "Vote Tracker" child for each Poll, sort of as seen below:

--Poll

----Choice 1

----Choice 2

----Choice 3

----Vote Tracker

------Vote1 (contains IP address)

------Vote2

------Vote3

------...etc

I guess I'm just curious if there is a better way to do this, or if there is any way to attach an array to each poll that could store the same information.

Thanks!

Share this post


Link to post
Share on other sites

Hi shawnadelic and welcome!

Check out soma's new module:

https://processwire.com/talk/topic/9299-pollino-simple-polls-for-processwire/

There really is no fool proof way of ensuring this sort of thing. Cookies can be cleared, IP addresses are usually not static and can be spoofed anyway. The best option is to require the user have a user account and that they be logged in, but if you are not concerned with complete accuracy, you can make use of a combination of techniques, which I believe soma's module allows for.

Even if the module doesn't suit your needs exactly, I bet you will find lots of useful code snippets and ideas in there.

I have built a couple of polls, one that relied solely on cookies, and one that required the users to be logged in, but have never gone the IP route, because in particular it might prevent users from the same house, place of work, or even the same ISP being able to vote.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for the reply!

It's not critical that the poll is 100% secure, so I'm trying to avoid requiring a login to allow as many people participate as possible. That being said, soma's IP logging in that module looks like exactly what I had in mind, so I am definitely going to check it out a little more closely. Thanks!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By dragan
      Is it somehow possible to limit the number of pages one can select with the page reference field?
      I have a case where I need to have exactly three, not more, not less. Is this doable with a hook? Or would you suggest another approach? (three single pageref fields and make each mandatory)
    • By chuckymendoza
      Hello together,
      I have a problem with the image field and in my case it seems that there is a limit of how much images can be in such field.
      The following case:
      I have around 20 pages. Each has a usual image field, where I can upload an unlimited number of images (array).
      Most of the pages got 50-200 images but one page got 411 images (I know, it’s much  )

      Now, when I change the order of one image (let’s say I drag & Drop the first image after the third) or delete one image by clicking on the trashcan, everything runs fine. BUT when I click SAVE the image won’t be deleted or moved to it’s new place. You can change anything else on the page - I have a text field there - and save it, no problem.
      Interestingly I can add (upload) new images but I’m not able to delete or move them.
      - The file size of the images are between 200kb and 1.7MB, RGB, JPGs.
      - When I duplicate the page and try to delete/move I got the same problem.
      - I also created a whole new page and got the same problem
      - Also tried a different server (virtual and online): same problem
      - ProcessWire 3.0.62
      So, is there a limited to the images field? Any clues except limiting the image files to max. +-200 images?
       
      Thanks so much in advance and have a great weekend.
      Thomas
    • By Peter Knight
      I have about 50 pages which are just containers for their child pages.
      What's the most efficient way to exclude these parent pages from Searches?
      I'm using Ryan's code here
       
      I guess I have a few options but is number 2 here the best way or is there anything I haven't considered which would be better?
      1. Mark as 'Hidden: Exclude from lists and searches"
      Isn't an option because it hides from lists which I use.
      2. Tell the selector to ignore a particular template(s)
      Sounds like a good approach
      3. Create my own checkbox called "Search Ignore" and add it into a selector
      Could work but it seems like a ton of work to manually edit all the pages I want to ignore
      Cheers
       
       
       
       
       
       
       
       
       
    • By MilenKo
      Hello guys. I am super happy to be passing to the final cleanup of my first custom build theme and to start applying the SEO optimization modules/code. I noticed something strange this morning and can't find out where exactly is my issue. Hopefully it is a quick fix or silly miss on my side.
      So here is the issue: I am generating a list of all my recipes in the db using the following query:
      <?php if($page->numChildren) { //Build a selector and limit page results to 10 $recipe_results = $page->children("limit=4"); //Assign results of the array to $listing foreach($recipe_results as $index => $listing) { //Limit the text content to 160 chars using the function in function.php $text = $sanitizer->textarea(truncate("$listing->recipe_intro_text", 160)); ?> Then follows the boring part of html insert of the variables, clases etc. The listing works fine. So as far as there would be more than the planned results per page, I implemented the page rendering using the following code:
      <!-- Pagination --> <?php echo $recipe_results->renderPager(array( //Show font awesome right hand icon for next page 'nextItemLabel' => __("<i class='fa fa-hand-o-right'></i>"), //Show font awesome left hand icon for previous page 'previousItemLabel' => __("<i class='fa fa-hand-o-left'></i>"), //Define the active class of current page 'currentItemClass' => "current", //Define the block markup code 'listMarkup' => "<ul class='page-nav'>{out}</ul>", //Define the item markup code and applying currentItemClass 'itemMarkup' => "<li class='{class}'>{out}</li>", //Generating the link appearance of all buttons 'linkMarkup' => "<a href='{url}'>{out}</a>", )); ?> <!-- Pagination --> And again, everything worked perfectly after I allowed page numbers. 
      So then I implemented a few similar queries in the sidebar of my website, listing content from other page parents/children. Here is one example:
      <?php $favorite_books = $pages->find("template=books-inner, sort=-random, limit=3"); foreach($favorite_books as $b) { if (count($b->book_images)) { $thumb = $b->book_images->first->size(70,60)->url; $desc = $b->book_images->first->description; } else { $thumb = $settings->small_thumb->url; $desc = "NoThumb"; } ?> <li> <div class="thumb"> <a href="<?php echo $b->url?>"> <img src="<?php echo $thumb?>" alt="<?php echo $desc?>"/> </a> </div> <div class="detail"> <a href="<?php echo $b->url?>"><?php echo $b->title?></a> </div> </li> <?php } ?>  
      It was all working fine, until I started browsing page 2, 3, etc. It appears for some reason, that the pageRendering is applied not only to $recipe_results, but also to all requests from the widgets. So on page 1, I get the proper number of recipes and proper number of results in the widgets (books in this example). If I browse to page two, I still see the proper recipes number and everything else, but the widgets show only 1 result (as far as I have imported 4 test posts only). On page 3, it shows notihing in the widgets, but recipes are OK again.
      As far as to render pages I am using $recipe_results and the pageRender is called for that variable, I am not sure why it is also applied to $favorite_books and other widgets. Any suggestions or ideas what is going on? I tried to change every variable on the page thinking that I might be having a call to the same one, but it is obvious in the example that they do not match...
    • By Hubris
      Hi folks,
      My maximum file size upload tops at 50Kb, no matter what the browser or OS.
      My PHP settings are:
      enabled extensions:
      imagick, imap , json, mailparse, mbstring , pdo , pdo_mysql  and pdo_sqlite
      options:
      allow_url_fopen On display_errors Off error_reporting E_ALL file_uploads On include_path .:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php log_errors On mail.force_extra_parameters no value max_execution_time 180 max_input_time 180 max_input_vars 1000 memory_limit 256M open_basedir no value post_max_size 128M session.save_path /tmp short_open_tag On upload_max_filesize 256M  
      These settings here changed based on some tips of other topics on this forum.
      On the field, there is no min/max image dimensions.
       
      Thanks!
×
×
  • Create New...