简体   繁体   English

将安全文件保存在PHP包含文件夹中

[英]Saving secure files in PHP include folder

On the Apache Server it is possible to define a directory for PHP includes. 在Apache服务器上,可以为PHP include定义目录。 The path to the include folder is out of root, and does not conflict with the server script. 包含文件夹的路径不在根目录中,并且与服务器脚本不冲突。 The reason why I think it is nice to store the secure files like config.php and db-access.php in the PHP global include folder, is that I don't have to define the path for each and every single page in my web application. 我认为将config.phpdb-access.php类的安全文件存储在PHP全局包含文件夹中的原因很好,是因为我不必为Web中的每个页面定义路径应用。 I can simply do as following: 我可以简单地执行以下操作:

<?
require_once('config.php');
require_once('db-access.php');
?>

But then I have a question cause, besides that the include folder is outside of root, is it still save enough? 但是然后我有一个问题原因,除了include文件夹在root之外,它是否还足够存储?

It will be save enough, it you wouldn't place it under your htdocs folder ( folder, which is accessible via you web server ). 它将足够保存,并且不会将其放在htdocs文件夹(可通过Web服务器访问的文件夹)下。 So, you can put it in any other places. 因此,您可以将其放在其他任何地方。

Way to include file from root directroy 从根目录DirectRoy包含文件的方法

<?php 
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= '/folder/config.php';
require_once($path);
?>

OR Use if they are in your public_html or www folder 或如果它们位于您的public_htmlwww文件夹中,则使用

 Order allow,deny
deny from all

use .htacces 使用.htacces

order deny,allow
deny from all

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

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