I'm engaged in the Herculean task of configuring Focus Lab Master Config with an MSM site. I'm trying to write some conditionals based on the site_id variable, but I keep getting errors.

Right now I'm just running this on my local server, so inside config/config.local.php, at the bottom, I put:

if ($config['site_id'] == '1') {
    $env_config['webmaster_email'] = '[email protected]';
} else {
    $env_config['webmaster_email'] = '[email protected]';

But when I do this it causes the page to crash (Error 330 (net::ERR_CONTENT_DECODING_FAILED): Unknown error.). The problem seems to be the site_id variable, because if I do something like:

if (1 == 1) {
    $env_config['webmaster_email'] = '[email protected]';
} else {
    $env_config['webmaster_email'] = '[email protected]';

Then everything is fine. I tried using $site_id instead of $config['site_id'], and I tried site_name instead of site_id but it's still not responding.

Any thoughts?

  • A tricky one indeed. First of all have you defined paths in each sites' index.php file as detailed in this gist?
    – Ian Young
    Apr 16, 2013 at 22:09
  • Hi Ian - I'm actually trying to do things a bit differently, hence the conditional, so I haven't mimicked that Gist.
    – kmgdev
    Apr 16, 2013 at 22:25
  • Config hasn't actually bootstrapped itself all the way at the point where you're trying to access it; the site_id variable might not be there yet. Let me do a couple experiments.
    – adrienne
    Apr 16, 2013 at 22:41

1 Answer 1


Due to the order in which EE determines and sets the site_id config item, I would recommend that any conditions that must be on the site_id value be avoided and you simply have those values saved to EE's database. In this case that would mean changing the Webmaster Email value in the Control Panel.

That said, most environment conditions are in place to override what's in production. Production is "king" in most scenarios so having the webmaster_email value in the database without a config override is perfectly acceptable. Then in your staging, dev or local environments you can override the value with something else.

I can't think of a case where a webmaster_email override would be different by site_id. Is it possible you could take this approach?

  • webmaster_email is purely for experimental purposes to see if the conditional even works. I'm trying to figure out how to set more important config variables like site_url and themes_path based on which site is currently being accessed. Unfortunately I'm starting to see that if you're on Site A editing Site B, there's really no way to tell Master Config which site is currently being accessed. I think this might be a dead end :/
    – kmgdev
    Apr 18, 2013 at 15:25
  • Yea the control panel is the tricky part because of how EE uses cookies to decide which site its using. You can check for a cookie for the site_id but you also need to know the cookie prefix for that. Apr 18, 2013 at 16:26
  • Hmm, yeah. You know more PHP than I, why doesn't this work? $_COOKIE[$cookie_prefix . '_cp_last_site_id']
    – kmgdev
    Apr 18, 2013 at 18:10
  • Is that in your config file? Apr 18, 2013 at 18:53
  • No, it's in config.local.php. If I put $_COOKIE['exp_cp_last_site_id'] it works, so I guess my syntax is wrong?
    – kmgdev
    Apr 18, 2013 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.