限制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?

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.