We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36341
    • 19 Posts
    Hi Friends,

    I want to share session in multiple sub-domains. let me explain little more
    suppose there are 2 domains 1) sub1.example.com and 2)sub2.example.com
    if user logs in to sub1.example.com and then opens sub2.example.com then MODx should show him
    logged in automatically.

    This is possible with plain php and i have tested it. we just need to add one line before session_start() ie ini_set(’session.cookie_domain’, ’.example.com’);

    I am using MODx login package and not sure where should i add this line. If someone know it please help me.
    thanks in advance
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      For Evo, in the manager/includes/config.inc.php file the function at the end of the file has this line:
              setcookie(session_name(), session_id(), $cookieExpiration, MODX_BASE_URL);
      

      You would need to add the .
              setcookie(session_name(), session_id(), $cookieExpiration, '.' . MODX_BASE_URL);
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 36341
        • 19 Posts
        scottwell thanks for the quick reply...
        i am using revolution...which file i am supposed to edit ??

        Do i need to make change in core->model->modx->modx.class.php
        line number 2856
        setcookie(session_name(), session_id(), $cookieExpiration, $cookiePath, $cookieDomain,$cookieSecure);
        to
        setcookie(session_name(), session_id(), $cookieExpiration, $cookiePath, ’.’.$cookieDomain,$cookieSecure);
          • 22303 MODX Staff
          • 10,725 Posts
          In Revolution, just add a System Setting with the key session_cookie_domain and the value of .domain.tld.
            • 36341
            • 19 Posts
            @scottwell : i added this system setting "session_cookie_domain", but still it doesnt works sad
            Below is what all i did,
            1) added this setting on both the MODx (sub1 and sub2 aswell) Just to make sure i tried if setting i just created is accessible to MODx...and yes "session_cookie_domain" is fetching the new value.
            2) As i have said before i created simple php pages outside MODx...and found that they share session i can see session created on sub1 is accessible on sub2.
            3) when i try to do it with login package...it again asks me for login even when i am logged in on sub...i also created same username password on both the domains.
            4) without using login package i simply set SESSION with "testing" key and some value...that also dont get shown on sub2 (which works if i do it outside of MODx)

            Is it problem with MODx or login system ??
              • 22303 MODX Staff
              • 10,725 Posts
              You must login to each Context explicitly.
                • 36341
                • 19 Posts
                U mean there is no way i can create centralized login system for 2-3 subdomains ??
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Yes, you configure the Login component to login to ALL the Contexts you want a user authorized in.
                    • 36341
                    • 19 Posts
                    @opengeek : Can u please explain it in more details....what exact changes i need to make into login package ??
                      • 29019 ☆ A M B ☆
                      • 104 Posts
                      Set the &contexts setting to include all of your contexts:

                      [[!Login? ... &contexts=`web,context1,context2,...`]]
                        www.darkstardesign.com

                        Are you in the Nashville area? Join us for our next MODX meetup!