简体   繁体   中英

PHP Prevent Direct Access

Is there any possible way to make direct browser access to

http://www.example.com/test.php

Not available when viewing url directly but still allowing

JQuery $.get('http://www.example.com/test.php') function

To read the file? I know this might not be possible because I believe going in my browser and typing http://www.example.com/test.php is basically the same thing on client side as using the $.get() function.. But I didn't know if there was any work arounds for this.

Kinda, have php check for the x-requested-with header. If it is not present, redirect somewhere else.

It doesn't stop someone from sending their own request with said header though.

You are right, using a browser or $.get are basically the same. The only difference is that an AJAX call sets the X-Requested-With header to XMLHttpRequest. This can be added with browser extensions, though, so it is not fool-proof.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM