Prevent external access to PHP scripts but allow AJAX

前端 未结 4 1499
挽巷
挽巷 2021-01-22 20:06

I\'ve read a lot about .htaccess rules, checking headers, using encryption etc.. but I haven\'t found exactly the answer I\'m after. I know that assuming the server is set up ri

4条回答
  •  情深已故
    2021-01-22 20:13

    There is NO way absolutely to safely/reliably identify which part of the browser the request comes from -- address bar, AJAX. There's a way to identify what is sending though browser/curl/etc via User-Agent header (but not reliably)

    A quick but a lot less reliable solution would be to check for the following header. Most browsers attach it with AJAX calls. Be sure to thoroughly look into it, and implement.

    X-Requested-With: XMLHttpRequest
    

    NOTE: Do not trust the client if the resource is cruicial. You are better off implementing some other means of access filtering. Remember, any one can fake headers!

提交回复
热议问题