Frage

I have an application with images that people can vote, and I want to check the ip of the user to disallow him to vote for a second time. What is the best approach for this, should I get the ip and fill in a .txt file and every time a user tries to vote ill check that file and if the ip is not in the file allow him?? or is there a better solution

War es hilfreich?

Lösung

You can get the user's like this:

$users_ip = $_SERVER['REMOTE_ADDR'];

Don't use text files (as this will be bad for your HDD, too much I/O); instead use database.

When user arrives at the vote script:

  • Check if this IP has a record in your db table
  • If the IP has a record, check when the user last voted and compare with current time
  • If the timespan from his last vote > what it should be, let him vote, update db table for that ip "last_vote"

  • If the user doesn't have a record in db (first vote); insert a db table row with the ip and current timestamp

Andere Tipps

You can also store cookie for a time interval. if a user vote for a question then save a particular cookie for that question like .

setcookie('voted'.$_POST['qid'], 'yes', time() + 4800 , "/");

If question is new then user can vote.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top