PHP absolute server path to website (the easy and fastest way)
8 Jun 2010

Here’s a quick note for all those people wondering what the absolute path to their server is. There are many tools and solutions around the Internet that help you find it, as well as php_info() but all of them seem overcomplicated. The easiest and quickest way to do it is by using a simple stupid trick:
Create a PHP file and add some invalid code such as random letters:

Now save your file as test.php and upload it to the web server root folder.
Open it with your browser, an error message like this should appear:
Parse error: syntax error, unexpected T_STRING in /home/w093jsf/hello/public_html/test.php on line 2
That’s it! The home path for this example is: /home/w093jsf/hello/public_html/.
Error not showing?
If you can’t see any errors you may need to enable the debugger by activating/displaying PHP error reporting.
Code to display PHP absolute path
Here’s the code ready to copy and paste:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
this be an errorz wohoooo!!
That’s it, get those 4 lines of code and paste them in a new file.
Living in United Kingdom? Read about the best mobile phone network in the UK.
Personal MBA
Get out while you can
And death came third
Universal Principles in Design
Comments
5 comments to PHP absolute server path to website (the easy and fastest way)
Brilliant! This solution is definitely great :)
June 8th, 2010 at 6:19 pmI have been looking for the PHP function but didn’t think that errors display the complete path to the file in the server.
Cheers!
Thats super cool!
You can also do this
$script_directory = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], ‘/’));
August 3rd, 2010 at 1:19 amAnd.. what about using the proper function to do this??
:)
Saludos desde España ;)
August 19th, 2010 at 8:48 pmoops no code allowed.. this was the function:
August 19th, 2010 at 8:49 pmok.. it doesn’t work.. there you have the link to that function http://es.php.net/manual/en/function.getcwd.php
August 19th, 2010 at 8:50 pm