1

我正在尝试将配置文件用于数据库和评级脚本,但问题是配置文件位于此目录中:

       website.com/include/config.php  aka websitename/include/config.php

评级脚本需要配置,访问方式如下: include_once("config.php");

我希望配置位于:“/files/website/” 网站根文件夹的上一级目录。

我一直在尝试:
“../files/website/”和其他变体,但无法弄清楚如何链接它们。

我已经设法放置一个配置文件并访问它,但是使用这个 ajax 评级脚本,它工作的唯一方法是将配置放在 /include/ 文件夹旁边:rating_process.php - 有这个链接:include("公司/config.php");

     rating_functions.php         - has this link : include_once("config.php");

     rating_total_functions.php   - has this link : include("inc/config.php");

希望我已经在这里解释了自己

对,现在看看我的主机:$_SERVER['DOCUMENT_ROOT']; 输出:/foldy/homepages/11/username/htdocs/webbysite

我的索引文件位于:/foldy/homepages/11/username/htdocs/webbysite/index.php 包含的评分脚本位于:/foldy/homepages/11/username/htdocs/webbysite/include/

我希望配置位于 /foldy/homepages/11/username/htdocs/secretfiles/config.php

我正在尝试如何退出:webbysite 文件夹,然后进入 secretfiles(兄弟文件夹)

我试过添加 ../ 等等,但显然缺少一些东西:(

4

3 回答 3

0

but the problem is the config file is in this directory

it is not a problem at all.
just keep it as is.

Concerning your particular problem, your problem is that you don't know where you want to put your file. /files/website/ is not likely a right path and it is apparently not one level high from webroot.

So, first of all make your mind about the right path to the directory and it's relative position to the web root

于 2012-05-02T20:27:44.727 回答
0

if you are concerned about security ( because your config file contains the db details ) i would place the db config file outside the site root folder and then require_once('../../dbConfig.php') from the script that's creating xml or json for your ajax

more exactly ... your site folder might be here: /var/www/html

set a virtual host (done differently on Linux and Windows) and point your domain to a sub folder inside /html so that the new path to the site root is /var/www/html/site.

then place your config file in /var/www/html and call it from your scripts inside your /site folder using require_once('../dbConfig.php)`.

your db details are outside the site folder

于 2012-05-02T20:29:02.027 回答
0

尝试

$configLocation = $_SERVER['DOCUMENT_ROOT'].'../files/website/config.php';
include_once($configLocation)
于 2012-05-02T20:25:04.293 回答