ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Control Panel Cookie Domain for MSM is "automatic"... and problematic

November 06, 2012 1:01pm

Subscribe [1]
  • #1 / Nov 06, 2012 1:01pm

    johndwells

    94 posts

    Hi Support,

    Setup:
    Running EE 2.5.2, MSM 2.1.3
    Example domain: http://www.domain.com (note the www for purposes of below explanation).
    MSM sites running in subfolders of that domain (e.g. http://www.domain.com/site2).
    ALL MSM sites access same CP at http://www.domain.com/admin.php

    Problem:
    Today’s cookie saga started when I tried to “Login as member” by Super Admin:

    Members > View All > Select a member > Member Administration > Login as member

    I would follow the steps, Submit the form to be returned to the CP, yet when I returned the CP, I was still logged in as my same Super Admin.  No matter that I tried, I’m unable to “switch” to being logged in as a different user.

    Through various hunting, I’ve tracked down a chunk of code which, when commented out, restores the ability to “switch”:

    system/expressionengine/core/EE_Config.php, starting around line 272 (all comments shown here are straight from EE_Config.php):

    // Control Panel Cookie Domain
    // Since the cookie domain changes based on the site chosen in the CP,
    // and since one could have multiple CPs, some using admin.php with path.php, 
    // we have to be a bit more creative in figuring out the correct, 
    // usable cookie domain for the CP 
    if (REQ == 'CP' && $this->item('multiple_sites_enabled') == 'y')
    {
     $this->cp_cookie_domain = '';
     
     if ($site_name != '')
     {
      $this->cp_cookie_domain = $this->config['cookie_domain'];
     }
     else
     {
      ...
     }
    }

    Within the ELSE block that I’ve omitted for brevity, the code ends up calculating the CP cookie domain by piecing parts of the $_SERVER[‘HTTP_HOST’] together. Due to its calculations, it sets my cp_cookie_domain to “.domain.com”, but if you note my example domain, I’m operating specifically on a domain with ‘www’ as the prefix.

    As soon as I comment out this entire chunk - from 272 to 336 - my CP returns to working perfectly.  I can log in as another member, log out, back in, as well as continue to successfully switch from one MSM site to another within the CP.  AND I can also log into another EE install on a parallel subdomain (e.g. http://www2.domain.com), again without problems.

    I have explicitly NOT set a cookie_domain through my config.php, index.php, admin.php, or otherwise.

    Could someone take a look at this and give any insight as to whether it’s “working” as it’s supposed to?  And in that case, what I’m doing wrong in my setup?

    Cheers,
    John

  • #2 / Nov 07, 2012 4:02pm

    Dan Decker

    7338 posts

    Hi John,

    The simple response is: MSM is not intended to run multiple sites in subfolders of a main domain. The intent is to run each site on a sub-domain or separate domain. You’ve already found out why that’s the case 😉

    However, that’s not to say it can’t be done - just not recommended.

    Suggestions to try:
    Un-comment the code you have commented out.

    Set a cookie domain in config.php - this will be installation wide.

    For each site’s index.php and admin.php set $assign_to_config[‘cookie_prefix’] = ‘subfolder’;

    That will force a distinct cookie for each sub-folder and should keep you from having to comment out code.

    Let me know your results!

    Cheers,

  • #3 / Nov 08, 2012 7:02am

    johndwells

    94 posts

    Hi Dan,

    Thanks for taking a look at this for me.  I’m surprised to hear you say that MSM is not recommended to run in subfolders, I’ve never encountered anything in the docs that would suggest that.  Would you have a link that discusses this?

    Meanwhile, I’ll try your steps again and report back with specific tests.

    Cheers,
    John

  • #4 / Nov 08, 2012 4:29pm

    Dan Decker

    7338 posts

    Hey John,

    Weeeeell… It’s not addressed directly, but the instructions *only* cover domains and sub-domains.

    Again, it can work - but you’ve bumped up against the reason it isn’t covered as an explicit means. The subfolder experience can be sub-optimal.

    However, I’m happy to work with you on the ins and outs of it.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases