Authenticate Subdomain

I have a sub-domain which I'm trying to restrict to authenticated Wordpress users but the authentication isn't working. I've tried the following code:

global $current_user; 
wp_get_current_user(); 
if ( is_user_logged_in() ) { 
    echo 'Username: ' . $current_user-user_login . \n; 
    echo 'User display name: ' . $current_user-display_name . \n; 
    } else { 
    wp_loginout(); 
    } 

This works if I use the URL domain.com/intranet/page.php but not on intranet.domain.com/page.php How can I get it to work for subdomains? I've tried adding the following to wp-config.php but that hasn't done anything:

define('COOKIE_DOMAIN', '.domain.com'); // Used to authenticate subdomains
define('COOKIEPATH', '/'); 

Any ideas?

Topic authentication Wordpress

Category Web


Ensure that COOKIEHASH has the same value for both, e.g.:

define( 'COOKIEHASH', md5( 'https://yourdomain.com' ) );
define( 'COOKIE_DOMAIN', '.yourdomain.com' );

See https://wordpress.stackexchange.com/a/264490/736

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.