duaabhuv188411 2011-05-02 14:11
浏览 66

数组查询PHP + mongoDB - 投票系统ips

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!

  • 写回答

2条回答 默认 最新

  • dongzhong9055 2011-05-02 14:20
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站