php to find the root url - Printable Version +- GetSimple Support Forum (http://get-simple.info/forums) +-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3) +--- Forum: Developer Discussions (http://get-simple.info/forums/forumdisplay.php?fid=8) +--- Thread: php to find the root url (/showthread.php?tid=15681) |
php to find the root url - Felix - 2020-12-21 Hi, We all know that with a php way finding the root path we can use $_SERVER["DOCUMENT_ROOT"] I am looking for a php way to get the root url of a website (so not with the GS api) I have not found a clear solution for it on php.net and neither on stackoverflow This is the best I could find: // do we have to do with http or with https $protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https'; // example php code to get the root url for http $root_url = "http://".$_SERVER['HTTP_HOST']; $root_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); It works but I am not sure if this is a fool proof way Does anyone know of a tested and fool proof php way to get the root url that works for localhost and for online site ? RE: php to find the root url - shawn_a - 2021-04-14 Look at how I do it in 3.4 |