0

I am using MultiSite WordPress. I want to set and get common variable in session/cookies for all sites.

My sites are:

NetWrok site:

http://www.sitename.com

SubDomain sites are:

http://hindi.sitename.com

and

http://urdu.sitename.com

The problem is when I set session value in "http://www.sitename.com" but not able to get that value in "http://hindi.sitename.com" and "http://urdu.sitename.com"

Is there any other solution to do this?

Thanks in advance

Gufran Hasan
  • 8,910
  • 7
  • 38
  • 51

1 Answers1

1

Using session cookies across subdomains is a well known problem: PHP Sessions across sub domains

However if you want to share common informations across your wordpress multisite sites the following may work (as :

$some_name = session_name("shared_multisite_sesssion");
session_set_cookie_params(0, '/', '.sitename.com');
session_start();

Use only cookies for sessions

session.use_only_cookies = 1
session.cookie_httponly = 1

Set the following parameteres in your WordPress config:

define( 'COOKIE_DOMAIN', '.sitename.com' ); // Dot prefix
define( 'COOKIEPATH',    '/' );
define( 'COOKIEHASH',    md5( 'sitename.com' ) );

However there are a few warnings you should take into account:

  • WordPress multisite sites are sometimes independent - as soon as they have their own domain this will not work anymore (Share a cookie between two websites)
  • WordPress multisite sites in many setups are intended to be individual sites with similar design. It may not be the best architectural idea to connect those sites via common sessions.
Blackbam
  • 17,496
  • 26
  • 97
  • 150
  • Check my updated answer - it should be working. Read $_COOKIE and $_SESSION in both installations. – Blackbam Apr 04 '18 at 12:33
  • Describe your problem more precise. Is it that the cookies cant be read or is it that they are red but the session is unknown? – Blackbam Apr 06 '18 at 11:14