1
I have searched here for the site and found nothing that could really help me. I believe some of you can help me.
The following is, I created a link that takes the ID of 'x' post through GET and every click on that link is performed an UPGRADE in the BD where it takes the previous number of clicks and counts +1, but if I click numerous times on that link will count numerous clicks.
I would like to know how I do to store the click of that particular user for 24 hours?
the code I use to upgrade clicks is below
<?php
$ID = filter_input(INPUT_GET, 'ID');
if(empty($ID) || !is_numeric($ID)){
echo '<script type="text/javascript">location="../";</script>';
}else{
$seleciona = $pdo->prepare("SELECT * FROM postagens WHERE ID = ? LIMIT 1");
$seleciona->bindValue(1, $ID, PDO::PARAM_INT);
$seleciona->execute();
$dados = $seleciona->fetchObject();
$n_status = $dados->CLIQUES + 1;
if($dados){
$stmte = $pdo->prepare("UPDATE postagens SET CLIQUES = :1 WHERE ID = :2");
$stmte->bindParam(":1", $n_status , PDO::PARAM_INT);
$stmte->bindParam(":2", $ID , PDO::PARAM_STR);
$executa = $stmte->execute();
if($executa){
echo '<script type="text/javascript">location="http://'.$dados->LINK.'";</script>';
}else{
echo 'Erro ao inserir os dados';
}
}
}
?>
You could add an extra column to the table that stores the click count. This column stores the last hour when there was a request
GET
. Then at the time ofUPDATE
you put an extra condition on yourWHERE
. Only increment the counter if the current time is longer than the last click time for at least 24 hours.– Oralista de Sistemas
That would help in part. But if I do this and determine for example, 1hr without change it would hurt me since in 1hr if other users click on the link there will be no change in the counter. That’s why I want to create the cache. It would be +/- that same line of reasoning you but I want that whenever a user click on that specific link create a cache on that person’s pc, then I make a condition where if the cache exists will not count the click, so if a thousand people click there will be a thousand clicks. but if a thousand people click 2 times there will still be a thousand clicks
– ivan veloso
I thought there was an accountant per user. Guilherme’s response is good.
– Oralista de Sistemas