Block direct access to PHP file except from AJAX request?

后端 未结 2 495
清歌不尽
清歌不尽 2021-01-01 06:41

I wish to have a webpage that uses AJAX to access a PHP file in ./ajax/file.ajax.php

Trouble is, I don\'t want people to be able to type the address in

2条回答
  •  感情败类
    2021-01-01 07:07

    If you're not using jQuery or you are not interested/you can't use custom headers (to go with what alex has offered), you may just simple POST some data with your Ajax request, and in that specific file check if that data has sent or not. If you send by GET it would be visible on the address bar, that's why I suggest POST.

    
    

    It's not solid as you can fool that with providing handmade data, however that's better than nothing if your problem is not that critical.

提交回复
热议问题