dqtu14636 2015-02-03 19:49
浏览 69
已采纳

限制JSON访问只能使用一次

I have JSON ajax call from jQuery, which returns user country through PHP geolocation. Now the problem is, some users have put that in their website, and I don't know why they did this, to spam me or what, but it calls JSON 20 times per second when someone is on their page, and each time it executes script on my server. Can I limit JSON return only once per page opening (through PHP return function or JSON code), does someone has any idea?

  • 写回答

1条回答 默认 最新

  • dongyao2022 2015-02-04 11:16
    关注

    Assuming you are using that GeoIP JSON capability from dynamic pages, you can add a random identifier, with something such as:

    $id = md5(random());
    

    Then save that $id in a session table and send it along the HTML.

    Change your jQuery script to include that identifier when the GeoIP request is sent to the server. On the server, you first check whether the $id sent by the jQuery exists in your session table. If not, then stop right there, and if you'd like, add the IP address to your firewall for a while that way you waste nearly no resources.

    The $id must be deleted after one use if you do not want to allow more than one use. That way even your page will not receive a GeoIP in return.

    You should use a similar session identifier for any form you use on your website. It is also possible to attach such to a cookie, but in Europe, they are big at asking people for not using cookies... so you may not want to do that anyway.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用