How do I restrict JSON access?

I think you might be misunderstanding the part where the JSON request is initiated from the user’s browser rather than from your own server. The static HTML page is delivered to the user’s browser, then it turns around and executes the Javascript code on the page. This code opens a new connection back to your server to obtain the JSON data. From your PHP script’s point of view, the JSON request comes from somewhere in the outside world.

Given the above mechanism, there isn’t much you can do to prevent anybody from calling the JSON API outside the context of your HTML page.

Leave a Comment