Support » Plugin: WordPress Native PHP Sessions » Multisite different session on each site.

  • Resolved trumor

    (@trumor)


    Hi,

    I’m working on a multisite where each site is a different language and I’m trying to implement geolocation redirection. I only want the user to be redirected once which is why I need to be able to use session variables. The problem I’m having is that each site seems to have a separate session. So the user gets redirected to another site in the network and there’s no session variable saying the user has already been redirected.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hi @trumor,

    Thanks for the report.

    Unfortunately, if the sites are on different domains, it won’t be possible to pass session data from one request to another. PHP session data is tied to the visitor with a domain-based cookie.

    What you might consider instead is including a query parameter (e.g. ?redirected=true) in the initial redirect, and using the presence of the query parameter to set a session on the target site.

    Hope this helps!

    Thread Starter trumor

    (@trumor)

    Hi Daniel,

    I’m using a subdirectory multisite so the domain name is the same. I think my problem across the multisite network is the cookie domain. I’ve tried this for my cookie domain settings.

    define('ADMIN_COOKIE_PATH', '/');
    define('COOKIE_DOMAIN', false);
    define('COOKIEPATH', '');
    define('SITECOOKIEPATH', '');

    I’ve also tried it with define(‘COOKIE_DOMAIN’, ”). If I understand the cookie domain settings correctly this should make all of the network sites use the same cookie.

    Also the session variables don’t seem to persist across pages. I have session_start() at the beginning of the init action but $_SESSION is always empty.

    I’m on WP Engine which I understand is very aggressive at caching. And I think that trying to use sessions the way I am would probably defeat the purpose of the cache. So I may need to find a different solution.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.