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 named 'DOCUMENT_ROOT'
$rd = getenv('DOCUMENT_ROOT');
// Echo the value of the 'DOCUMENT_ROOT' environment variable
echo $rd . "\n";
?>
Output:
I:/Ampps/www
Flowchart:
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?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics