3

I'm having some issues sharing the user sessions across two installs.

(a) site on http://stolenmx.com (b) site on http://arcade.stolenmx.com

I have installed B in the same database as A and I have defined the user and user_meta tables so I am sharing user data and users etc but I can't seem to bridge the sessions.

I have tried using cookies a few different ways but nothing works.

This is what I'm using in (b) wp-config at the moment with no effect,

define('COOKIE_DOMAIN', 'www.stolenmx.com');
define('COOKIEPATH', '/');     

does anyone know how to get this working?

I'm actually using UserPro on site (a) to manage registration and login and I have wp-login.php disabled. Could this be why cookie isn't working cause UserPro saves the cookie elsewhere or just simply doesn't use one?

5
  • Have you tried cookie domain stolenmx.com? (without the www) And make sure the security keys in both your config files all match. Apr 9, 2015 at 13:49
  • Hey, yep, I have done this but it has no effect on either site. I coppied the salts etc so they match and tried changing the cookie domain but nothing?
    – Crafty Mc
    Apr 9, 2015 at 14:30
  • Try .stolenmx.com - notice the dot prefix. Apr 9, 2015 at 15:19
  • Tried it mate, no difference.
    – Crafty Mc
    Apr 9, 2015 at 15:24
  • Found the culprit, see answer. Apr 9, 2015 at 16:29

2 Answers 2

5

You also need to define a matching COOKIEHASH for both sites - a random 32 bit string will do.

By default, COOKIEHASH is an MD5 hash of the site URL, and is used to generate the default names for all authentication-related cookies. Hence why, at the moment, your cross-domain login isn't working (the names of the cookies aren't consistent, as COOKIEHASH will be different for each site).

See wp_cookie_constants() for more information.

So to recap, your wp-config.php for both sites should look like:

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

define( 'CUSTOM_USER_TABLE',      'wp_users' );
define( 'CUSTOM_USER_META_TABLE', 'wp_usermeta' );
6
  • How would i define it? just add this to both wp-config.php? $cookiehash = md5("stolenmx.com"); define('COOKIEHASH', $cookiehash );
    – Crafty Mc
    Apr 9, 2015 at 20:28
  • Yes, that'll do :) Apr 9, 2015 at 20:29
  • Perfect bud, I will try it right now and let you know in about 3 mins if it works :)
    – Crafty Mc
    Apr 9, 2015 at 20:29
  • Okay so it kind of works lol, when I login to site (b) I'm also logged into site (a) but when I logout of (b) it doesn't log me out of (a)? however when logging in to site (a) it doesn't log me in to site (b). So all that's working is logging into site (b). Any ideas?
    – Crafty Mc
    Apr 9, 2015 at 20:43
  • See my revision. Make sure you're testing in a clean browser (i.e. completely wipe history/cookies). I can't offer much more help, it works for me! Apr 9, 2015 at 20:55
1

In addition to TheDeadMedic's answer, both sites must share the same keys and salts in the wp-config.php files (I replaced the string with four zeros):

define('AUTH_KEY',         '0000');
define('SECURE_AUTH_KEY',  '0000');
define('LOGGED_IN_KEY',    '0000');
define('NONCE_KEY',        '0000');
define('AUTH_SALT',        '0000');
define('SECURE_AUTH_SALT', '0000');
define('LOGGED_IN_SALT',   '0000');
define('NONCE_SALT',       '0000');

I created a blog post about this which has more details: https://www.tekfused.com/wordpress/sharing-login-cookies-among-wordpress-installs/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.