Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess甚至阻止php访问_Php_Linux_Windows_.htaccess - Fatal编程技术网

.htaccess甚至阻止php访问

.htaccess甚至阻止php访问,php,linux,windows,.htaccess,Php,Linux,Windows,.htaccess,我想拒绝访问包含数据库详细信息的txt文件,但使用当前方法,我发现即使脚本也无法访问所需的详细信息。我将定期将此设置从windows移动到linux,然后再返回,因此需要一个不易损坏的解决方案 # Refuse direct access to all files Order allow,deny Allow from 127.0.0.1 Deny from all 不是最安全的方法,但您可以在文档\u ROOT/.htaccess文件中使用类似的规则: RewriteEngine On R

我想拒绝访问包含数据库详细信息的txt文件,但使用当前方法,我发现即使脚本也无法访问所需的详细信息。我将定期将此设置从windows移动到linux,然后再返回,因此需要一个不易损坏的解决方案

# Refuse direct access to all files
Order allow,deny
Allow from 127.0.0.1
Deny from all

不是最安全的方法,但您可以在
文档\u ROOT/.htaccess
文件中使用类似的规则:

RewriteEngine On

RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com/ [NC] 
RewriteRule ^secret\.txt$ - [F,NC]
用txt文件名替换
secret.txt
,用实际域名替换
yourdomain.com


这将阻止从任何地方访问
secret.txt
,除非推荐人来自您自己的网站。

我建议使用更安全的方法(例如在代码中)存储数据库详细信息。这些细节变化不大谢谢你的建议。但在这种应用中,这是理想的方法。如何将txt文件存储在不可通过web访问的目录中?同样,由于此应用程序的性质是不断在windows和linux上重新部署,因此理想的方法是在可通过web访问的文件夹中。不太理想,我知道