如何解决如何使文件只能由PHP访问?
我有一个PHP脚本,应该可以抓取数据库,并且我不希望该数据库被公开访问。我该怎么做,以致无法像https://example.com/database.file
一样查看文件,但PHP文件仍然可以抓取它。
上次我尝试禁用对该文件的访问,但是每次我尝试访问该文件时,PHP文件都返回403。
接下来,我在此网站上查看了两个问题,但没有一个可以回答我的问题。
解决方法
您可以在apache / nginx中为文件设置重定向条件以拒绝外部使用。
在Apache中:
<FilesMatch "^(database\.file)$">
Require all denied
</FilesMatch>
在Nginx中:
location = /database.file {
deny all;
return 404;
}
,
如果要隐藏文件,则IMO最简单的方法是通过重写URL重定向到404文件(“找不到文件”页面)。
类似:
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
Integer n = sc.nextInt();
ArrayList<Integer> li = new ArrayList<Integer>();
while(true){
System.out.println("Please enter coin value: ");
li.add(sc.nextInt());
System.out.println("Do you want to add more yes/no?");
String answer = sc.next();
if (answer.equals("no")){
break;
}
}
Integer arr[] = new Integer[li.size()];
arr = li.toArray(arr);
}
URL重写不会影响直接包含文件系统结构的PHP包含/要求或RewriteRule "^folder/myFile\.php$" "404.html" [QSA,L]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。