Array query PHP + mongoDB - voting system ips

By : mrkva
Source: Stackoverflow.com
Question!

can you maybe help me please? I'm making my voting system in php + mongodb, and I would like to keep the ip addresses which already voted. What would be to best way? I was thinking about doing it like this:

$ip=$_SERVER['REMOTE_ADDR'];
$ipData = array('$push' => array('ips' => $ip), '$inc' => array('votes' => 1));
$collection->update(array( '_id' => $id), $ipData);

Is this the best way to do it? How would you than compare all the elements of the ips array to see if the ip already didn't voted? The list will look like (192.168.0.1, 127.0.0.1, 123.45.67.8).

Thank you!

By : mrkva


Answers

compare the user's ip with the array of IPs using the PHP function in_array()

http://php.net/manual/en/function.in-array.php



Use a Unique Index and a UPSERT:

$collection-
By : Alix Axel


This video can help you solving your question :)
By: admin