简体   繁体   English

PHP禁止直接访问

[英]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. 我知道这可能是不可能的,因为我相信在浏览器中键入http://www.example.com/test.php与使用$ .get()函数在客户端基本上是相同的。不知道是否有任何解决方法。

Kinda, have php check for the x-requested-with header. Kinda,让php检查x-requested-with标头。 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. 没错,使用浏览器或$ .get基本上是相同的。 The only difference is that an AJAX call sets the X-Requested-With header to XMLHttpRequest. 唯一的区别是AJAX调用将X-Requested-With标头设置为XMLHttpRequest。 This can be added with browser extensions, though, so it is not fool-proof. 但是,它可以与浏览器扩展一起添加,因此并非万无一失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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