logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: php :: DOCUMENT_ROOT not working correctly
Author
rahenkamp



Joined: 08 Aug 2006
Posts: 7

PostPosted: Wed 09 Aug '06 17:09    Post subject: php :: DOCUMENT_ROOT not working correctly Reply with quote

Hi,

I just moved a bunch of code that I have from a MacOXS apache environment and for the includes that I use on the site I use require_once($_SERVER["DOCUMENT_ROOT]."/include/filename.php")

I am finding that this is not working as expected and since I am new to the Windows Apache environment I like to find out how you guys handle reletive referencing for include files.

TIA

d
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Wed 09 Aug '06 17:14    Post subject: Reply with quote

That is a bit tricky. It depence from the pathsetting in httpd.conf to run the script unter *nix, Windows, and Mac OS try

Code:

$this_dir=substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/")+1);
Back to top
rahenkamp



Joined: 08 Aug 2006
Posts: 7

PostPosted: Wed 09 Aug '06 17:45    Post subject: Reply with quote

James Blond wrote:
That is a bit tricky. It depence from the pathsetting in httpd.conf to run the script unter *nix, Windows, and Mac OS try

Code:

 $this_dir=substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/")+1);


This does not quite work for me. I have the following folder structure.

ROOT |
|Grades|
index.php
| admin <-folders in grades
| classes
| includes
| faculty
| skins


if I use what I have always used ,which lets say, I need to load a skin I would have used:

include_once($_SERVER['DOCUMENT_ROOT']."/grades/skins/$SKIN/header.php");

which would have produced: (in the mac environment)

/library/webserver/documents/grades/skins/forestgreen/header.php

if I do a straight substitution of $_SERVER['DOCUMENT_ROOT'] with $this_dir from the code above I would get on the windows server this:

/grades/admin/skins/forestgreen/header.php

When I really need /grades/skins/forestgreen/header.php

If I directly use $_SERVER['DOCUMENT_ROOT'] in the windows environment I would get:

C:/Apache2/htdocs/grades/skins/forestgreen/footer.php

which is the correct physical path but when I do a require_once the script comes to a halt.

This is a HUGE problem for me if I can't resolve it.


Thanks again for your help

d
Back to top
pnllan



Joined: 05 Dec 2005
Posts: 221

PostPosted: Wed 09 Aug '06 18:22    Post subject: Reply with quote

Per relative reference:

admin is a sub of grades right? If so, and I have a file in admin and want to refernce to a file in the docroot then:

../../aFileInTheDocroot.php

Next, if I have a file in admin and want to reference to the skinsfolder then:

../../skins/aFileInSkinsDir.php
Back to top
rahenkamp



Joined: 08 Aug 2006
Posts: 7

PostPosted: Wed 09 Aug '06 18:51    Post subject: Reply with quote

pnllan wrote:
Per relative reference:

admin is a sub of grades right? If so, and I have a file in admin and want to refernce to a file in the docroot then:

../../aFileInTheDocroot.php

Next, if I have a file in admin and want to reference to the skinsfolder then:

../../skins/aFileInSkinsDir.php



I have done that with no results and in fact is one of the ways I normally code. This is a new install as per the instructions on this site. Initially the install had some problems. I am totally stumped on this and I am under deadline to get it done.

Again my setup

root/grades

with

/admin
/classes
/includes
/skins

located in /grades

If I am trying to load a skin within the /admin folder I have always used:

include_once($_SERVER['DOCUMENT_ROOT']."/grades/skins/$SKIN/header.php");

If I do an echo($_SERVER['DOCUMENT_ROOT']."/grades/skins/$SKIN/header.php") in windows the result is:

c:/apache2/htdocs/grades/skins/forestgreen/header.php

which is the correct path but the include or require fails.


Grrrrrr

This works perfectly in MacOSX apache but breaks in Win apache. I am at my wits end on this. I have googled this till the cows come home and I am not getting any results.

Thanks

d
Back to top
pnllan



Joined: 05 Dec 2005
Posts: 221

PostPosted: Wed 09 Aug '06 19:07    Post subject: Reply with quote

I understand your issue very well, and have seen it before. I would need to see the code, it has to be something in it. Most likely it is a sensitivity to paths (Mac v. Win) issue. Without seeing the code, use a PHP reference and note Windows specifics with regards to paths (require and include specifically).

If you post code, just post what is pertaint to this issue.
Back to top
rahenkamp



Joined: 08 Aug 2006
Posts: 7

PostPosted: Wed 09 Aug '06 19:53    Post subject: Reply with quote

pnllan wrote:
I understand your issue very well, and have seen it before. I would need to see the code, it has to be something in it. Most likely it is a sensitivity to paths (Mac v. Win) issue. Without seeing the code, use a PHP reference and note Windows specifics with regards to paths (require and include specifically).

If you post code, just post what is pertaint to this issue.


<?
$SKIN="forestgreen";

echo($_SERVER["DOCUMENT_ROOT"]."/grades/skins/$SKIN/footer.php");

include($_SERVER["DOCUMENT_ROOT"]."/grades/include/config.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/include/functions.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/skins/$SKIN/header.php");

?>

This only produced the result of the echo which is:

C:/Apache2/htdocs/grades/skins//footer.php

Please note that the variable $SKIN did not show in the result.

Nothing is included. ZIP, NADA

Since this is a new install do you thing that perhaps that is where the issue might lie?

Thanks

d
Back to top
pnllan



Joined: 05 Dec 2005
Posts: 221

PostPosted: Wed 09 Aug '06 20:55    Post subject: Reply with quote

I just noticed that $SKIN is part of the string rather than being added to the string. What happens when you concatenate the variable SKIN as such:

Code:
echo($_SERVER["DOCUMENT_ROOT"]."/grades/skins/".$SKIN."/footer.php";
include($_SERVER["DOCUMENT_ROOT"]."/grades/include/config.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/include/functions.php");
include($_SERVER["DOCUMENT_ROOT"]."/grades/skins/".$SKIN."/header.php");

rather than:

echo($_SERVER["DOCUMENT_ROOT"]."/grades/skins/$SKIN/footer.php"
...
...
include($_SERVER["DOCUMENT_ROOT"]."/grades/skins/$SKIN/header.php");

You need to concatenate the Variable SKIN into the string like you did the GLOBAL Variable as shown in the above code block.
Back to top


Reply to topic   Topic: php :: DOCUMENT_ROOT not working correctly View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner