CG_dude Posted April 14, 2009 Share Posted April 14, 2009 Hello Freaks, I'm building a php site, I have all .php extensions in the web root. I have some .txt files that php includes under the web root. My question is, can you run a php page from under the web root? If so, where can you tell php to also look under the webroot to access the page. I'm thinking maybe the ini, config, or htaccess files? but not sure, and not sure how to make the change? Any help would greatly be appreciated, thanks Quote Link to comment Share on other sites More sharing options...
CG_dude Posted April 14, 2009 Author Share Posted April 14, 2009 Let me be more specifice. I have this site, testsite.php it's web root is /opt/hpws/apache/htdocs/testsite.php I want to run a link off the testsite.php to a php page that is located in the same path but in a directory just under the web root.(/opt/hpws/apache/htdocs/prod_report_archives/mondays_report.php) Hope this helps Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 can you run a php page from under the web root? of course you can. the address to the file would be... http://www.yourwebsite.com/prod_report_archives/mondays_report.php Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 By default things that are below the webroot can be accessed in "webspace" by providing their relative path. That isn't a PHP function so much as an apache function. The webroot can be thought of as a "changed root" in that, as far as people accessing the website are concerned the path to those documents starts at the "root" ie. "/". Apache hides the details from the outside world in regards to the true path of those documents. So, as noted, in embedded links, you just refer to the path starting from the webroot. However when dealing with include or require_once etc, you need to specify the real path of the scripts, or if you prefer, you can specify an include path, where every directory acts as a php root, and will find scripts that are specified as relative to the path. This allows php to include scripts that are not even in "web space" which may be a security feature you desire, depending on the application. One comment about your use of .txt files. It's always preferable to have your includes be .php files, because these will be parsed by the web server, should someone attempt to access them directly. For example, if I have the file foo.txt in webspace and I access it as http://www.yoursite.com/foo.txt, unless you've taken steps to prevent it, the contents will be returned to the user. A .php version of that file will not suffer from the same issue, since the PHP parser will process the file and return the results. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.