pwired Posted December 20, 2020 Share Posted December 20, 2020 Hi, To find the root url of a website we can use the processwire api I am looking for a php way to get the root url of a website (so not with the 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 HTTP OR HTTPS $protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https'; // example php code for http $root_url = "http://".$_SERVER['HTTP_HOST']; $root_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); So far this works but I am not sure if this is the real php fool proof way. Does anyone know of a php fool proof way to get the root url that works for localhost and online site ? Link to comment Share on other sites More sharing options...
bernhard Posted December 22, 2020 Share Posted December 22, 2020 You should get some good inspiration here: https://github.com/processwire/processwire/blob/d8945198f4a6a60dab23bd0462e8a6285369dcb9/wire/core/ProcessWire.php#L410-L459 ? 2 Link to comment Share on other sites More sharing options...
Recommended Posts