I am using Apache server for PHP. How can I retrieve my web root in PHP, like http://localhost/testthesis/
?
For your webservers root directory, use:
$folder = '/';
For the directory of the retrieved script, use:
$folder = './';
For your webservers root directory, use:
$protocol = $_SERVER['HTTPS'] == '' ? 'http://' : 'https://';
$folder = $protocol . $_SERVER['HTTP_HOST'];
For the directory of the retrieved script, use:
$protocol = $_SERVER['HTTPS'] == '' ? 'http://' : 'https://';
$folder = $protocol . $_SERVER['HTTP_HOST'] . '/' . basename($_SERVER['REQUEST_URI']);
Here is one way of doing it:
$web_root = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/";
OUTPUT -->http://website.com/parent_folder/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With