PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 3, 2022

[FIXED] How to set and get common variable in session for MultiSite WordPress?

 July 03, 2022     multisite, session, wordpress     No comments   

Issue

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


Solution

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.


Answered By - Blackbam
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing