Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7649979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:07:58+00:00 2026-05-31T11:07:58+00:00

We discovered bugs in our site after deploying from our localhost development environment to

  • 0

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:

     $_SERVER['HTTP_HOST']

We use that to construct paths to various files used by our website.

For example:

         // 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";

Here is the crux of the problem:

  • on our localhost machine, $_SERVER[‘HTTP_HOST’] resolves to ‘localhost‘ — 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 unaware of which website folder involved — we have to append it.

  • but on our staging server, $_SERVER[‘HTTP_HOST’] resolves to ‘http://www.ourWebSite.com‘.
    In that case we don’t need to append anything — the staging web server returns our website folder.

Have we thought of a couple kludgy inelegant ‘snide-remarks-in-code-reviews’ workarounds. Yes.

But I’m thinking there’s a better way — any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:07:59+00:00Added an answer on May 31, 2026 at 11:07 am

    The config file is the correct answer.. I use an default and override set up.
    In config.php

    $config = array('url' => 'http://production.url'); // 'conf1'=> 'var1', etc
    $dev_config = array();
    @include_once('dev-config.php');
    $config = array_merge($config, $dev_config);
    

    In dev-config.php you add any overrides to the $dev_config

    $dev_config['url'] = 'http://localhost/ourWebSite';
    

    Then in production, I just delete the dev-config file. Super easy, works flawlessly.

    If you want to keep it the way you have it, this can also be solved with an http.conf tweak on your dev box. You need to set your documentRoot to what ever it is now plus the /ourWebSite that way http://localhost/ will point to the same folder with in your code as http://production.url/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently discovered that I am affected by this bug http://www.mail-archive.com/mono-bugs@lists.ximian.com/msg71515.html Well, at
I discovered that it is possible to extract the hard-coded strings from a binary.
I discovered Microsoft's .Net charting controls from another post here, and so far I
Today I discovered that my fresh installation of Apache HTTP Server is able to
I've discovered that any time I do the following: echo '<a href=http:// title=bla>huzzah</a>'; I
I recently discovered that relying on default encoding of JVM causes bugs. I should
How do you know that as many bugs as possiblle have been discovered and
I discovered a nice abstraction whereby I can read in data from UDP using
I discovered(*) today that, depending on the server, my TSQL commands were case-sensitive, meaning
I'm writing a direct3d application and after noticing strange bugs such as anti-aliasing occurring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.