w3resource
php Programming Exercies

PHP Exercises : Get the document root directory as defined in the server's configuration file

PHP : Exercise-25 with Solution

Write a PHP script to get the document root directory under which the current script is executing, as defined in the server's configuration file.

Sample Solution: -

PHP Code:

<?php
// getenv() gets the value of an environment variable
$rd = getenv('DOCUMENT_ROOT');
echo $rd."\n";
?>

Flowchart:

Flowchart: Get the document root directory as defined in the server's configuration file

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to get the name of the owner of the current PHP script.
Next: Write a PHP script to get the information about the operating system PHP is running on.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming