开发者

If page called directly then throw 404

开发者 https://www.devze.com 2023-01-10 01:28 出处:网络
I have created a page on a WordPress site called AJAX which lives here: domain.com/ajax/ This page is used for AJAX calls. What I want to 开发者_C百科prevent is direct access to it, so basically allow

I have created a page on a WordPress site called AJAX which lives here: domain.com/ajax/ This page is used for AJAX calls. What I want to 开发者_C百科prevent is direct access to it, so basically allow JS to call the page but if someone types in the url and tries to access it on its own then they will get a 404 (basically making it as though the page doesn't exist)

The page has its own template file so can have a nice bit of PHP to detect this, but what would that code be? Thanks.


You can check header "X-Requested-With" for XmlHttpRequest, but this isn't 100% secure solution.


You can make the Ajax file require a Get or Post variable. Redirect the user to other page if that variable is not passed.

0

精彩评论

暂无评论...
验证码 换一张
取 消