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.
- I've tried href="../test.php", and it doesn't work (404 - File or directory not found)
- Permissions for test.php are the same as wwwroot (through the cp portal)
- I don't want to include the php file, I want to call and run it separately
- I've looked at every related post in stackoverflow for two days and nothing seems to work
- If your suggestion is to use a full path to the file or create a virtual directory, please include an example. Because I've tried both with no luck
- I've also read you would need php script to access php files outside the root, but have no idea how to call the outside file. I've tried this once, but got a 404 exception. Would be great if it worked
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