AJAX only access

前端 未结 5 1406
迷失自我
迷失自我 2020-11-30 11:31

I have recently started to code heavily AJAX supported scripts in PHP, thing is, the files being accessed by the AJAX calls can be directly used too, how to disable that?

5条回答
  •  无人及你
    2020-11-30 12:04

    There's no way of directly disallowing access. Since a query can always be crafted to match any criteria you come up with.

    If XmlHttpRequest is being used to query the server it adds a header which can be detected using something like:

    /* AJAX check  */
    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
      //Do something here
    }
    

提交回复
热议问题