DharmeshPHP Posted December 7, 2012 Share Posted December 7, 2012 Hey guys. So I'm re-coding my vote page for my RSPS as it's boring and outdated. I've created an auth system where users type the auth given after voting. However, I have a slight problem. I'm not quite sure on how to check if a user has voted before the 12 hour limit. When a user submits the button, the time() is stored onto the DB alongside with their auth code, ip and what not.. Could anyone help me out here? Please! Quote Link to comment https://forums.phpfreaks.com/topic/271734-how-to-check-if-user-has-voted-before-time-limit/ Share on other sites More sharing options...
DharmeshPHP Posted December 8, 2012 Author Share Posted December 8, 2012 Please guys? anyone.. ?:/ Quote Link to comment https://forums.phpfreaks.com/topic/271734-how-to-check-if-user-has-voted-before-time-limit/#findComment-1398219 Share on other sites More sharing options...
PFMaBiSmAd Posted December 8, 2012 Share Posted December 8, 2012 This is the description line from the forum section you posted in - Do you need help with some code you wrote? What code have you written and what error, symptom, or problem did you have when you ran it? If you are stuck at trying to figure out how you might do this, take a piece of paper and list out the steps you would do to accomplish this task in person, because programming is like writing a math-word-problem and then solving it - A person walks up at a timed-voting place, you write down the starting time, the id number you assigned (auth code), a description of the person (ip address/user agent) so that you can identify the person to make sure s/he didn't trade their id number with someone else; then when s/he comes back to vote, you check the id number/description to find the start time you previously wrote down and compare it with the current time and decide if s/he can vote. Quote Link to comment https://forums.phpfreaks.com/topic/271734-how-to-check-if-user-has-voted-before-time-limit/#findComment-1398220 Share on other sites More sharing options...
DharmeshPHP Posted December 8, 2012 Author Share Posted December 8, 2012 Ahh I'm sorry. Here is the code I've written. <?php mysql_connect("localhost", "**", "**")or die("Failed to connect" . mysql_error()); mysql_select_db("**")or die("failed to select DB" . mysql_error()); $authcode = substr(uniqid(),7,5); $host = gethostbyaddr($_SERVER['REMOTE_ADDR']); $ip = $_SERVER['REMOTE_ADDR']; $time = time(); if(isset($_POST['submit'])) { $sql = mysql_query("SELECT * FROM `authvote`"); if (mysql_num_rows($sql) > 0) { while ($row = mysql_fetch_array($sql)) { if ((time() - $row['time']) > strtotime("+1 minute", $row['time'])) { mysql_query("DELETE FROM `votes` WHERE `auth` = '" . $row['auth'] . "'"); echo 'Yodfu have already voted. wait ' . strtotime("+1 day", $row['time']); } else { echo 'You have already voted. wait ' . strtotime("+1 minute", $row['time']); } } } else { mysql_query("INSERT INTO authvote (auth, time, host, ip) VALUES ('$authcode', '$time', '$host', '$ip')")or die(mysql_error()); echo 'sdfdsfhanks for voting. Your auth code is: ' . $authcode; } } ?> <html> <form method="POST"> <input type="submit" name="submit" value="get auth"/> </form> </html> Quote Link to comment https://forums.phpfreaks.com/topic/271734-how-to-check-if-user-has-voted-before-time-limit/#findComment-1398226 Share on other sites More sharing options...
DharmeshPHP Posted December 9, 2012 Author Share Posted December 9, 2012 Bump .. Please anyone? :/ Quote Link to comment https://forums.phpfreaks.com/topic/271734-how-to-check-if-user-has-voted-before-time-limit/#findComment-1398348 Share on other sites More sharing options...
Jessica Posted December 9, 2012 Share Posted December 9, 2012 "What code have you written and what error, symptom, or problem did you have when you ran it?" You did one of these things. It sounds like all you need to do is add an if(). Time is easy to do math with. What have you tried?? Quote Link to comment https://forums.phpfreaks.com/topic/271734-how-to-check-if-user-has-voted-before-time-limit/#findComment-1398400 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.