简体   繁体   中英

can someone help me fix this code to once per day ip?

I am working on a voting system with personal vote links. I want to make the personal vote page to register IP and make sure the IP can only vote once per day per person( creator ). The vote page looks like this:

http://forum.thestronghold.nl/vote4creators.php

Can someone help me fix the vote link page? For now it looks like this:

$sql = "UPDATE `DB3121646`.`vote4creator` SET `Votes` = Votes +1 WHERE `vote4creator`.`id` = 6;";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo " Creator : " . $row["Creator"]. " "." Votes : ".$row["Votes"]."<br>";

    }
} else {
    echo "";
}

$conn->close();
?>
<?php
/* Redirect browser */
header("Location: http://forum.thestronghold.nl/vote4creators.php");

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

what you have to do is (simple, but not ideal solution):

  1. generate $uid = uniqueid(); per voter
  2. add uid to voters cookie with expiry date calculated to today's midnight+ 1sec
  3. on every new vote system have to check visitors if cookie exists (!exists = new visitor and/or not voted today)

additional you can:

  1. add this uid to database with her/his ip ( eid (int unsigned) | voter_ip varchar(16) | voter_uid varchar(32) will do the job done)
  2. and check cookie aginst database (select count() where voter_ip = $_SERVER['remote_host'] and voter_uid = $_COOKIE['vote_hash']) - (it's pseudocode, so validation is needed)
  3. if (rows == 0) { not voted } (if you wish to give them two votes per day just check if (rows <2) )

i hope it will guilde you to solve your problem.

btw: uncle google if full of examples how to do that in many ways ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM