I have a PHP page (“An API”) that does server-side stuff (e.g. entering info into a database) based on GET string input.
Would it be possible for me to secure it so that only the JavaScript code on a specific site can access the api, including securing it against, for example, someone typing into a JavaScript console while on the site?
No, it is impossible to completely protect against that.
You may, however, make it more difficult. For example:
Refererheader to point to that page (some browsers don’t sendReferer, however)X-Requested-Withbeing equal toXMLHttpRequestif the JS library you’re using sets that.