WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Subdomains and login persistence. (6 posts)

  1. barrybell
    Member
    Posted 6 years ago #

    Bit of background: my blog is set up so that each category appears as a subdomain, so I have http://category1.myblog.com, http://category2.myblog.com, http://category3.myblog.com, etc...

    Prior to WP2.3, I was using the following plugin to allow logins that were persistant across each of these subdomains - so that I could display a consistant "Hi, [name] - you are logged in!" type of message on every subdomain, so no matter where the user was on the site, he/she knew they were logged in.

    function sd_wp_login($arg){
      $cookiepath = COOKIEPATH;
      $blogurl = get_bloginfo('url');
      $blogurl = substr($blogurl, 7);
      $blogurl = str_replace("www.", ".", $blogurl);
    
      $cuser = "wordpressuser_".COOKIEHASH;
      $cpass = "wordpresspass_".COOKIEHASH;
      setcookie($cuser, "", time() + 31536000, $cookiepath, $blogurl);
      setcookie($cpass, "", time() + 31536000, $cookiepath, $blogurl);
    
      setcookie($cuser, $_POST['log'], time() + 31536000, $cookiepath, $blogurl);
      setcookie($cpass, md5(md5($_POST['pwd'])), time() + 31536000, $cookiepath, $blogurl);
      return $arg;
    }
    
    function sd_wp_logout($arg){
      $cookiepath = COOKIEPATH;
      $blogurl = get_bloginfo('url');
      $blogurl = substr($blogurl, 7);
      $blogurl = str_replace("www.", ".", $blogurl);
    
      $cuser = "wordpressuser_".COOKIEHASH;
      $cpass = "wordpresspass_".COOKIEHASH;
      setcookie($cuser, "", time() + 31536000, $cookiepath, $blogurl);
      setcookie($cpass, "", time() + 31536000, $cookiepath, $blogurl);
      return $arg;
    }
    
    add_filter('wp_login', 'sd_wp_login');
    add_filter('wp_logout', 'sd_wp_logout');

    However, since WP2.3, I believe cookies and authentication are now handled slightly differently. Can anyone help me out with creating a plugin (or tweaking my current plugin) that will allow logins and authentication to be persistent across subdomains in WP2.3 and higher? I've already tried and failed miserably on this one.

    Thanks in advance for your help - and if I can get this sorted, I'll definitely owe you a pint!

  2. barrybell
    Member
    Posted 6 years ago #

    Ok, solved it. Wrote a simple plugin that creates an additional logged_in cookie that's shared across subdomains when a user logs on, and which also destroys this extra cookie when the user logs off.

    The effect is that I can display a persistent and consistent user name and a 'you are logged in' type message on every subdomain of the blog.

    It's safe enough as it only replicates the logged_on cookie and NOT the auth_cookie which handles entry to the backend.

    Phew.

  3. marcrue
    Member
    Posted 6 years ago #

    I'm in a similar but not equal situation, we work with 8 subdomains, and each has its own wordpress installation, but they are all related. Do you think your solution may work even if there were different wordpress installs instead of vhost?

  4. vurea
    Member
    Posted 5 years ago #

    could you share how you got it working? ^__^

  5. wmrom
    Member
    Posted 5 years ago #

    barrybell,
    I am in the same situation. My blog has multiple users and each has a subdomain as a 'profile' or 'user-info' page, but login info doesn't persist. Could you give me a link to where I can find the plugin, or at least email it to me? webmaster(AT)culturalgadfly(DOT)com.

  6. wmrom
    Member
    Posted 5 years ago #

    vurea,
    I found a plugin that fixed the problem:
    root Cookie Path
    http://www.linickx.com/archives/466/root-cookie-for-wp26root-cookie-for-wp26

Topic Closed

This topic has been closed to new replies.

About this Topic