phphtmlsecuritydocument-rootwindows-hosting

Call PHP file outside wwwroot folder (Windows host, Arvixe)


Quick Solution (thanks to Tom's Answer below, read his for full explanation): Create a new php file in the webroot directory; let's say temp.php. From there, use include or request to call the test.php file that's outside the webroot.
index.html -> temp.php -> test.php
- I'm using javascript to go to temp.php, but href can be used too.
- In temp.php, I used: include dirname(__FILE__). '/../test.php';
- And that's it, test.php can't be accessed directly by URL. If you want to go to a file inside webroot from outside, use something like: header("location:".dirname(__FILE__).'/../wwwroot/index.php'); See: http://stackoverflow.com/questions/13550471/php-include-file-in-webroot-from-file-outside-webroot, Where I found FILE/DIR stuffs

Original Problem:
I have a website hosted on Arvixe (Windows Hosting, not Linux).
In my domain directory, I have a test.php file and the wwwroot folder.
Inside the wwwroot folder, I have an index.html file.

From the index.html file, I just want a simple link/button that calls the test.php file. I don't want users to have direct URL access to the php file (that's why I put it outside the root directory), but I want other files like index.html to access it. I've tried web.config and .user.ini stuff for security (which haven't work), but I figure if this works, then security should be fine.

Does anyone have a simple way to accomplish this? (Especially anyone working with Windows Arvixe hosting). I feel like there should be a simple answer here ): Thanks for reading this far and thank you very much for any suggestions


Solution

  • Some PHP script has to be web-accessible. If you don't want your main PHP script to be web-accessible, you still need another web-accessible PHP script to call the main script. There is no way around this unless you introduce an additional technology like SSI.

    It makes no difference if you use Windows or not for what you're asking.