Jump to content

PHP how to find the root url


pwired
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...