Search code examples
phpjsonapache.htaccess

I want to hide json file from public access. How do I do that?


I got a website, and the javascript file is loading a json file(using getJson) into options of one select element based on previous select option.

But in the mean time, public can access that json file directly.

I only want server can access this file and loads corresponding options in theselect element. But I don't want public can access that json file directly(avoid them downloading and such..)

How do I do this? Via htaccess? or sth else? I tried 'FILES' rule in htaccess but the server cannot access the json file either.


Solution

  • Javascript running at client side, so your visitor can get any resource used by javascript. If you want to hide anything, you need to replace your javascript code by server-side generation.