hey devlin,
I just coded the ip-block for re-votes via ip tracking in the database . I just block ip´s that are younger than 10 minutes. That is combined with the session check and a cookie.
It´s not a big problem if someone finds a way to vote twice by changing ip or disable cookies.
I just want to prevent someone clicking 20 times in 2 seconds.
I would do that to check if it´s a proper counter :)
here is my final code:
public function countUp(){
if(!isset($_COOKIE['liked-' . $this->ID]) && Session::get('liked-' . $this->ID) == false){
Session::set('liked-' . $this->ID, 'true');
setcookie('liked-'.$this->ID, time(), time()+3600*24*365, '/');
if($this->checkIpVoted()==false){
$vote = new ILikeVote();
$vote->Timestamp = time();
$vote->VotedPageID = $this->ID;
$vote->IP = $_SERVER['REMOTE_ADDR'];
$vote->write(); //write to d
//increment the counter of the page
$this->Counter = $this->Counter+1;
$this->writeToStage('Stage');
$this->publish("Stage", "Live");
}
}
}
private function checkIpVoted(){
$ret = false;
$time = time();
$timeLimit = $time - 600;
$vote = DataObject::get_one(
$obj = "ILikeVote",
$filter = "IP = '{$_SERVER["REMOTE_ADDR"]}' AND VotedPageID = {$this->ID} AND Timestamp > {$timeLimit}"
);
if($vote){
$ret = true;
}
//get old votes and delete them
$oldVotes = DataObject::get(
$obj = "ILikeVote",
$filter = "IP = '{$_SERVER["REMOTE_ADDR"]}' AND VotedPageID = {$this->ID} AND Timestamp < {$timeLimit}"
);
if($oldVotes){ //delete old votes of that ip (older than 10min)
foreach($oldVotes as $vote){
$vote->delete();
}
}
return $ret;
}