地图只能由网络服务器访问,其他用户无法访问
在我的网站上,我使用了很多包含内容,大多数包含内容只能由网络服务器访问,而不能供世界其他地方访问。因此,如果我在网站的页面中包含“../include_map/file.php”,则世界上其他用户应该无法使用 URL 进行请求(“website.com/include_map/file.php”) 。是否可以使用包含文件来保护地图,以便只有网络服务器可以包含这些文件?
On my site i use a lot of includes, the most of the includes should only be accessible for the webserver and not for the rest of the world. So if i include "../include_map/file.php" in a page on my site, it should not be possible to request with an URL by other users in the world ("website.com/include_map/file.php"). Is there a possibility to protect the map with the include files so that only the webserver can include the files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 可以包含服务器硬盘上任何地方(也包括非公共目录)的文件。
例如,如果您的 htdocs 位于 /var/www/domain/htdocs/ 中,您还可以包含位于 /var/www/domain/include_map 中的文件,而网络服务器将不允许从那里读取(如果配置正确)。
然后您可以测试使用 www.yourdomain.com/../include_map/file.php 访问该文件。
如果您仍然可以这样访问它,则您的网络服务器配置需要注意以防止其他人读取您的日志和其他内容。
另一种方法是通过 .htaccess 或 apache 配置拒绝对该目录的访问。 php 仍然可以包含这些文件,而用户无法从互联网访问它们。
在 apache 配置中,您可以执行以下操作:
在 .htaccess 文件中,您可以编写
.htaccess 文件应位于您想要保护的目录中。请咨询您的服务器提供商,了解哪种方式最适合您。正如评论中所述,您必须首先确定 .htaccess 是否适合您。
PHP can include files from everywhere (also non public directories) on the servers harddrive.
for example, if your htdocs is located in /var/www/domain/htdocs/ you can also include files located in /var/www/domain/include_map while the webserver wont be allowed to read from there (if configured properly).
you can then test to access the file with www.yourdomain.com/../include_map/file.php.
if you can still access it like this, your webservers configuration needs some attention to prevent others from reading your logs and other things.
another way is to deny access to the directory via .htaccess or apache config. php can still include the files, while users cant access them from the internet.
in the apache config you would do something like:
in a .htaccess file you could write
the .htaccess file should be located in the directory you want to secure. Consult your server provider to find out which way is best for you. As stated in the comment you have to find out if .htaccess is an option for you first.
你可以按照zuloo说的做。如果你希望它在任何条件下都能工作,你可以使用一个常量。
文件包括:
包含的文件:
You could do as zuloo said. If you want this to work under any condition you could use a constant for this.
The file including:
The included file: