title: $_SERVER['HTTP_HOST'] different on localhost versus deployment staging server
body: <p>We discovered bugs in our site after deploying from our localhost development environment to our staging server.
  We narrowed the bugs down to the following PHP code snippet:</p>
  
  <pre><code>     $_SERVER['HTTP_HOST']
  </code></pre>
  
  <p>We use that to construct paths to various files used by our website.</p>
  
  <p>For example:</p>
  
  <pre><code>         // EXAMPLE #1 -- THIS WORKS ON OUR LOCAL MACHINE
        $theSelectedImage = "http://" . $_SERVER['HTTP_HOST'] . "/ourWebSite/egyptVase.png";
  
          // EXAMPLE #2 --BUT IT MUST BE THIS TO WORK ON THE STAGING SERVER
        $theSelectedImage = "http://" . $_SERVER['HTTP_HOST'] . "/egyptVase.png";
  </code></pre>
  
  <p>Here is the crux of the problem:</p>
  
  <ul>
  <li><p>on our localhost machine, <strong>$_SERVER['HTTP_HOST']</strong>   resolves to '<strong>localhost</strong>' -- notice we then need to append our website folder name like I show in EXAMPLE #1 above.  I.E. on our localhost machine, $_SERVER['HTTP_HOST'] is <em>unaware</em> of which website folder involved -- we have to append it.</p></li>
  <li><p>but on our staging server, <strong>$_SERVER['HTTP_HOST']</strong>   resolves to '<strong>www.ourWebSite.com</strong>'.
  In that case we don't need to append anything -- the staging web server returns our website folder.</p></li>
  </ul>
  
  <p>Have we thought of a couple kludgy inelegant 'snide-remarks-in-code-reviews' workarounds.  Yes.</p>
  
  <p>But I'm thinking there's a better way -- any ideas?   </p>