Forum Moderators: coopster

Message Too Old, No Replies

Document root issue

php include path problem

         

tabish

9:01 am on Jul 8, 2008 (gmt 0)

10+ Year Member



Hi,

I have setup my Apache and PHP on windows machine.

All the site folders are put under "htdocs". Now suppose I have a website called "business" i have put that under "htdocs/business"

I have a file test.php under business directory in which i have written code;

include ($DOCUMENT_ROOT."/include/config.php");

the result of above says no file found under c:/apache/htdocs/includes/config.php, while my file is under c:/apache/htdocs/business/includes/config.php

Now.. I am not sure if Dcoument root should be used here or not.. because it is showing the path of htdocs while all my sites arte in different directories.

Please suggest..

Regards

mvaz

9:14 am on Jul 8, 2008 (gmt 0)

10+ Year Member



include ($DOCUMENT_ROOT."/include/config.php");

I think it should be include ($DOCUMENT_ROOT."/includes/config.php");

(You have missed the 's' at the end of include in your statement.

tabish

9:17 am on Jul 8, 2008 (gmt 0)

10+ Year Member



oh.. that was just typo here.. my question is something else if you read it carefully.

mvaz

9:41 am on Jul 8, 2008 (gmt 0)

10+ Year Member



As $_SERVER is a super global, you could try:

<?php
include($_SERVER['DOCUMENT_ROOT' ."/includes/config.php");
?>

tabish

9:52 am on Jul 8, 2008 (gmt 0)

10+ Year Member



I don't know if you still got what i am asking..

Thank you anyway.

tomda

10:03 am on Jul 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
$http_dir = "/business";
include($_SERVER['DOCUMENT_ROOT'].$http_dir."/includes/config.php");
?>

penders

11:10 am on Jul 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Now suppose I have a website called "business" i have put that under "htdocs/business"
:
Now.. I am not sure if Dcoument root should be used here or not.. because it is showing the path of htdocs while all my sites arte in different directories.

This looks like you really have just 1 website (the DOCUMENT_ROOT returns the directory of the root of your website as seen by the server), with several sub directories which you are calling websites. (Unless you are intending these to be sub domains?)

What I think you should be doing is actually setting up multiple websites (virtual hosts) on your web server, then DOCUMENT_ROOT will return the appropriate root directory depending on which site you are on...?
XAMPP/Apache for multiple websites [webmasterworld.com]