Jump to content

Document root question


AvDav

Recommended Posts

Hello, I am new in PHP, how can I get the full system path of web-server's root document (e.g. htdocs)? I tried $_SERVER['DOCUMENT_ROOT'] or just global variable $DOCUMENT_ROOT the interpreter says that it is undefined... I also made a deep search in google on this issue and read that this way of getting the docroot is not relieble. So my question is how can I get docroot using php code which will work on _every_ environment?
I have this idea: I will search for httpd.conf file in the system, and parse till the point of docroot definition, however this seems to be not flexible, e.g. if there should be other httpd.conf-s I need to know which one is the current real conf file for httpd deamon.
I am writing a short script which will process some files in docroot, and the requirment is that the root directory should be determined automatically, I cannot specify the path using, e.g. config file or command line argument.

Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/32038-document-root-question/
Share on other sites

[quote author=matto link=topic=120119.msg492507#msg492507 date=1167304919]
Trying to parse httpd.conf files could differ from system to system...

what do you get when you use the following:

[code]
<?php
echo $_SERVER["DOCUMENT_ROOT"];
?>
[/code]
[/quote]
I get nothing, blank string.
Also I tried:
[code]
if(isset($_SERVER["DOCUMENT_ROOT"])) echo "set";
else echo "not set";
[/code]
and got output 'set'.

Note that the solution should be such that there will be no need to make some php/apache/system configuration changes, because this script might be used from a person who has no idea how to change them etc.
Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.