Reputation: 151
I am trying to create a like button next to a user comment the problem is a malicious user could spam the button and it would query the database many time for validity, this is a problem. I thought about implementing a time-stamp check using CodeIgniter's Sessions but it is not working correctly. Example:
if ($this->session->userdata('last_activity') + 30 < time())
echo 'ok';
else
echo 'NOT ok';
The 'like' button uses AJAX, any ideas on how to prevent spam on the server side?
Upvotes: 0
Views: 387
Reputation: 176
You can try this alternative solution i.e., you can create a link as "LIKE" and "UNLIKE". When the user clicks on "LIKE" update the status (lets say to 1) to that particular post or comment and while displaying check for the logic that if status == 1 it should show the "UNLIKE" OR else "LIKE" link . And when the user clicks on "UNLIKE" update the status (lets say to 0) for the same. So, from this can provide spam clicks and will only show one link at a time.
Upvotes: 1