Jump to content

Recommended Posts

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! :)

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.

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>

"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??

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.