dpecb06062 2017-02-09 00:07
浏览 4

从复选框名称中过滤ID

I have some checkboxes that can be checked. They look like

<input type="checkbox" name="order[123]" value="1">

Now I am checking the formdata and I filter the ids in the order-array this way, before i look them up in the database.

$orderids = preg_grep('/^\d+$/', array_keys($_POST['order']));

is there a more efficient way for doing this?

  • 写回答

1条回答 默认 最新

  • douzhi3779 2017-03-12 15:09
    关注

    Using regex, you are ensuring no malicious strings are used, but not checking for viability in the database. (e.g. order[999999999999999999999999] would pass regex, but not be useful in the db.)

    The truest validation would be to run them against your database-borne ids using array_intersect.

       $valid_ids=array_intersect(array_keys($_POST['order']),$db_orderids_array)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line