ryanmetzler3 Posted May 25, 2014 Share Posted May 25, 2014 (edited) I downloaded a script for a poll/voting kinda thing for all my site visitors a while ago and then I tweaked it a bit. It is linked to a database. It grabs the question and possible answers from one database. It also stores user votes, ip addresses, and the date they voted in a database. I went to change the question and possible answers in my poll by simply changing the options in the Database. This worked fine, but I found a big problem! If you have already voted in the poll, then it displays the results to you every time you visit the site . I assumed this was based off your IP since it is recorded in the database. So logically I thought if you cleared all the IP's in the DB, then the new question would display for every user, but to my alarm it is based off cookies. This is problem because even though I changed the question and options, if people have not cleared their cookies from the last time then the poll still displays the results even though they have not voted on the new question yet. Is there someway to clear everyone cookies or make the poll start fresh for everyone without drastically changing the code and how the entire thing works? Edited May 25, 2014 by ryanmetzler3 Quote Link to comment Share on other sites More sharing options...
ryanmetzler3 Posted May 25, 2014 Author Share Posted May 25, 2014 I have a poll on my website. If you vote, then it registers a cookie and displays the results. It will continue to show the results even if you refresh the page because of that cookie. My problem is if I change the question then I want it to start fresh. Unfortunately if the user has not cleared their cookies from the last time they voted, it automatically displays the results even if the question was updated. I tried something like this: $_COOKIE = array(); this does not work because then it always clears it every time anyone visits. I just need to somehow wipe everyone's clean once when I update the question?? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 25, 2014 Share Posted May 25, 2014 your two threads have been merged together. don't start multiple threads for the same problem. Quote Link to comment Share on other sites More sharing options...
ryanmetzler3 Posted May 25, 2014 Author Share Posted May 25, 2014 your two threads have been merged together. don't start multiple threads for the same problem. yea sorry about. I though I could simplify my question a lot better but could not figure out how to delete the old one. Quote Link to comment Share on other sites More sharing options...
ryanmetzler3 Posted May 25, 2014 Author Share Posted May 25, 2014 (edited) I have a poll on my website. The question and answers for the poll are stored in a database. When I want to change the poll I simply change the question and answer options in the database. Here is the problem. When you vote it registers a cookie and then knows to display the results rather than the question. Like so: setcookie("voted".$_POST['pollid'], 'yes', time()+86400*300); Unfortunately when I change the question the old cookies are still in place. So it is automatically showing the results to the new question even if you only already voted on the previous question. Is there a way to detect if you voted on the old poll, and clear your cookie if you voted on the old one?. Really lost on how to solve this. I was thinking something like this: if(some constraint to distinguish old cookies maybe a time-stamp?){ $_COOKIES = array(); } Edited May 25, 2014 by ryanmetzler3 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 25, 2014 Share Posted May 25, 2014 (edited) "voted".$_POST['pollid'] that fact that there's a pollid that the cookie is keyed to, implies that the question, answers, and poll results also use the pollid. you would create a new/different poll by inserting the new question/answers using a different pollid, that would then also store the results and make a different cookie name for that new pollid. i'm betting the script has a 'create/insert' new poll interface that would do this for you. Edited May 25, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.