Jump to content

Running PHP under web root?


CG_dude

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.