PHP站点内置本地,需要使用.htaccess传输包含路径和安全文件

时间:2012-08-13 21:15:52

标签: php .htaccess webserver localhost php-include

我正在本地创建一个网站。

我的路径在我的网站上看起来像这样:(我知道它们是用脏的方式写的......)

在php中:

include 'C:\wamp\www\horticole/inventaire/pages-parts/listing/next-page-module.php';

in html:

background:url(http://localhost/horticole/images/header-bg-small.jpg);

// other example : 
<img src="http://localhost/horticole/inventaire/photos/indisponible.jpg" />

那么,php文件和html文件的替换接受链接是什么? ) 例如,对于包含,我在这里做什么:(假设我的网站名称是www.urmom.com

include 'www.urmom.com/inventaire/pages-parts/listing/next-page-module.php';

//or
include 'http://www.urmom.com/inventaire/pages-parts/listing/next-page-module.php';

//or
include 'public_html/inventaire/pages-parts/listing/next-page-module.php';

//or what ?

另外,如果我包括这个:

include '(site)/pages-parts/database-settings.php';

它会安全吗?有人可以访问我的数据库设置或它可以这样吗?它可能看起来很愚蠢,但是人们可以包含我的文件并使用我的变量吗?

我唯一获得的是PDO请求。我将使用ctrl + f一次性替换所有链接,因此我希望确保它在向公众提供任何内容之前能够正常工作。我还希望只有脚本中的“includes”和“require”才能访问“(site)/ pages-parts”或其他文件夹中的文件,而不是访问者。什么是.htacces代码放在这个文件夹的.htacces文件中呢?

1 个答案:

答案 0 :(得分:0)

要包含文件,您可以使用以下内容:

require_once($_SERVER['DOCUMENT_ROOT'] . '/pathtofile.php'); 

关于include '(site)/pages-parts/database-settings.php';

的安全性

这取决于该文件中的内容。但是,从较高的层面来看,保护该文件的方法是将其从文档根文件夹中移出