I am using apache server for php. How can i retrieve my web root in php like http://localhost/testthesis/ help me please
either:
'http'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
or:
dirname(__FILE__);
on a file in the webroot, save it in a global or a registry if you want to use it in subdirs.
Web root is always just /
you'd never need hostname or protocol part
and root can be only root of the server, not some folder or file
if you need some path, like /testthesis/ - thre are ways, but it has nothing common with web root
if you need filesystem dir for the webroot - it's in the $_SERVER['DOCUMENT_ROOT'] variable
What you're looking for is not a webroot but rather a URL.
You can get your current URL like so:
$protocol = strpos($_SERVER['SERVER_SIGNATURE'], '443') !== false ? 'https://' : 'http://';
$url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
for relative paths:
for your webservers root directory, use:
$folder = '/';
for the directory of the retrieved script, use:
$folder = './';
for absolute paths (from client's perspective):
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']);