Home PHP - Best way to keep track of IPs that voted
Reply: 1

PHP - Best way to keep track of IPs that voted

Paul Diamant
Paul Diamant Published in 2018-02-14 19:21:28Z

I am making a small side project on which guests can vote on some sort of posts with either agree or disagree, then I want to save the IP that voted in the database. I was thinking of saving an array of IP's that voted in the 'posts' table, however that might be insufficient I guess. Would a separate table like the following be recommended?; post_votes: post_id, IP Doesn't matter if the user voted agree or not, as long as the vote is counted they won't be able to vote again. What's the best approach for this? Thanks in advance.

Dominik Reply to 2018-02-14 20:30:52Z

Yes, the best way is to use a seperate table with identifiers (e.g. post_id) to identify the posts. Never save more than one information per field - saving the information in an array in the same table is cruel.

However, do NOT store the IP address 'as is' in the database as this is illegal in many countries and can cause a lot of trouble! Instead use a hashing function like hash_hmac (http://php.net/manual/de/function.hash-hmac.php), hash the IP address and save the hash instead.. Because hashes are one-way functions, this will ensure anonymity for the user but still give you the opportunity to prevent users from voting several times.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30467 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO