AvDav Posted December 28, 2006 Share Posted December 28, 2006 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 More sharing options...
matto Posted December 28, 2006 Share Posted December 28, 2006 Trying to parse httpd.conf files could differ from system to system...what do you get when you use the following:[code]<?phpecho $_SERVER["DOCUMENT_ROOT"];?>[/code] Link to comment https://forums.phpfreaks.com/topic/32038-document-root-question/#findComment-148696 Share on other sites More sharing options...
AvDav Posted December 28, 2006 Author Share Posted December 28, 2006 [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]<?phpecho $_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. Link to comment https://forums.phpfreaks.com/topic/32038-document-root-question/#findComment-148700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.