Find out the root path on your server in PHP

Well just a quick post, I’ve started using a new host recently and i’ve been installing oscommerce. Part of oscommerce’s installation process requires the root address on the server to the files but the host didn’t seem to disclose this information so i found the following line of PHP which does the trick.

1) Create a page i.e. root-test.php

2) Add the following line of code to the page:

Remove the spaces appropriately from around the question marks:

< ? = $_SERVER['DOCUMENT_ROOT']; ? >

3) Upload the file.

4) Then go to the file online i.e. http://www.yourdomain.com/root-test.php

It will then give you the appropriate results i.e.

/home/1234/username/www.yourdomain.co.uk/public_html/

Useful piece of code!

Leave a comment