WordPress.org

Forums

Universal Login for 13 Blogs (43 posts)

  1. Alex.R
    Member
    Posted 3 years ago #

    Hello everyone,

    I need some guidance in linking user privileges for 13 blogs located in all these sub-domains.

    --------------------
    ab.jobortunity.ca
    bc.jobortunity.ca
    mb.jobortunity.ca
    nb.jobortunity.ca
    nl.jobortunity.ca
    ns.jobortunity.ca
    nt.jobortunity.ca
    nu.jobortunity.ca
    on.jobortunity.ca
    pe.jobortunity.ca
    qc.jobortunity.ca
    sk.jobortunity.ca
    yt.jobortunity.ca
    --------------------

    What has been done so thus far?

    1. I have installed WordPress 3.2.1 to allsub-domains, with individual prefix for every single one on of them into one database.

    2. I wanted all users to share one _users table and one _usermeta table, to have universal login and registration privileges across all these sub-domains.

    So, I saved and modified my first blogs _users, _usermeta tables from the database to my computer in a sql format. I then renamed the tables as universal_users and universal_usermeta, the same was done inside these user tables. Saved and uploaded back onto the same database.

    3. After all that was done, the following took place, I have added the following code to all the wp-config.php files.

    define('CUSTOM_USER_TABLE', 'universal_users');
    define('CUSTOM_USER_META_TABLE', 'universal_usermeta');

    Went back to the website, and performed a test. I encountered the error: ‘You do not have sufficient permissions to access this page.‘.

    So, I went back to the wp-config.php file, and changed the code to use the original _usermeta of each blog, but left the universal_ prefix for users. Went back to test, and it worked. I could use one admin username accross all 13 blogs, so I desided to add a new user named "testuser" and see If I can post on all blogs, and for sure it worked like a charm.

    4. I noticed one problem, when inside dashboard as "testuser" the extra details for the profile did now follow, such as firs name, last name, etc. Because the _usermeta was not universal.

    So then I went back on Google to do more research, since now I need one _usermeta file across all the blogs, but without the error for the login. So I went back to research on Google, and came accross this page: http://wordpress.org/support/topic/how-to-use-2-blogs-with-the-same-users?replies=17

    5. After reading the whole article, I resided this is what needs to be done, and to give it a try.. Uploaded the wp-settings.php file onto my machine, and looked for:

    $wpdb->users = $wpdb->prefix . 'users';

    and

    $wpdb->usermeta = $wpdb->prefix . 'usermeta';

    but they are no where to be found.. so what now? I'm confused, did these change in the 3.2.1 version?

    I checked the capabilities.php file, and the code I need to change is there:

    $this->cap_key = $wpdb->prefix . 'capabilities';

    Any help would be greatly appreciated. Or if this has been covered before for the new version of wp, and could possibly point me in the right direction. Thank you in advance, and sorry for the long read.

  2. Paul Clark
    Member
    Posted 3 years ago #

    It'd be much less trouble (and hacking) to just setup one multisite install. Multisite uses a global users table by default, and allows you to run all sites off the same WordPress core files (easier upgrades).

    If setting up multisite with subdomains is too complex, you can use a subdirectory structure with the Domain Mapping plugin.

  3. meloniq
    Member
    Posted 3 years ago #

    Leave file "wp-includes/capabilities.php" unmodified,

    choose one "main blog installation" which will hold users data,

    fill in every other blog "wp-config.php" file data of main blog

    define('CUSTOM_USER_TABLE', 'MainBlogPrefix_users');
    define('CUSTOM_USER_META_TABLE', 'MainBlogPrefix_usermeta');

    and as a final step install on all blogs plugin "WP Orphanage" which will care about User Roles

    Plugin URL: http://wordpress.org/extend/plugins/wp-orphanage/

  4. Alex.R
    Member
    Posted 3 years ago #

    meloniq thank you so much, works like a charm.

  5. Alex.R
    Member
    Posted 3 years ago #

    Hey meloniq, would you possibly know how to fix the cookies issue. When I visit the other sub-domains I'm still prompted to log in. How would I be able to make it so that members are kept logged in even if they visit the other sub-domains? I couldn't find any plugins related to this.. so I figured I would ask you, or anyone else that might know the solution. Thanks in advance.

  6. meloniq
    Member
    Posted 3 years ago #

    Hi,

    Include in all "wp-config.php" files value (replace value with Your domain name - not subdomain, "dot prefix" is important)

    define('COOKIE_DOMAIN', '.YourDomain.Com');

    And the same keys to all "wp-config.php" files, You can generate it on this site:
    https://api.wordpress.org/secret-key/1.1/salt/

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

    Clear cookies in web browser for Your website(s) and check hows working now;)

  7. Alex.R
    Member
    Posted 3 years ago #

    Okay I'll get on it right now.. one thing though, all wp installations are in subdomains, there is no wp installation on the root, would `define('COOKIE_DOMAIN', '.jobortunity.ca');
    ` still work on all sub-domains?

  8. meloniq
    Member
    Posted 3 years ago #

    Yes, in Your case it should be:

    define('COOKIE_DOMAIN', '.jobortunity.ca');

  9. Alex.R
    Member
    Posted 3 years ago #

    Okay, I've generated new keya, and added same salt keys to all wp-config files, and also added define('COOKIE_DOMAIN', '.jobortunity.ca');

    I decided to test on two sub-domains, activated the stock themes wordpress comes with:

    http://on.jobortunity.ca & http://ab.jobortunity.ca

    Cleared my cookies, via ccleaner for all my browsers. Logged in to Ontario, but when I visit Alberta, I still need to log in. Any suggestions?

  10. Sven01
    Member
    Posted 3 years ago #

    Hey Meloniq,

    First I want to say: nice post !

    I did what you wrote, but I have a question (or 2)

    Is it necessary to use "WP Orphanage"? I use role scope allready...
    On my second site I can only NOT log in anymore: http://stoofvlees.eu/wp-login.php?redirect_to=http%3A%2F%2Fstoofvlees.eu%2Fwp-admin%2Fprofile.php&reauth=1
    Any suggestions?

    Thank you!

    Or somebody else know what I can do?

  11. meloniq
    Member
    Posted 3 years ago #

    Hi Sven01,

    I don't know this second one plugin, don't know how it works...
    If You are not a admin on second blog (cant access administrative panel), open phpMyAdmin and change roles to administrator for this user.

  12. Sven01
    Member
    Posted 3 years ago #

    Hi Meloniq,

    You are quick to answer :)
    I am admin for both blogs, and I could login before I changed the settings.
    Now it redirects me to the login page after I tried to login.

  13. meloniq
    Member
    Posted 3 years ago #

    Just redirect? or there is some information whats wrong?
    Try to use other web browser or clear cookies

  14. Sven01
    Member
    Posted 3 years ago #

    I tried ie, googlechrome and opera :-(
    on g-chrome it gives me this in my browserwindow: http://stoofvlees.eu/wp-login.php?redirect_to=http%3A%2F%2Fstoofvlees.eu%2Fwp-admin%2Fprofile.php&reauth=1 and a new login screen.
    I just want that my users have 1 login for all my blogs and if possible that they kept login when they change blog.
    I did change :
    define('AUTH_KEY', 'XYZ');
    define('SECURE_AUTH_KEY', 'XYZ');
    define('LOGGED_IN_KEY', 'XYZ');
    define('NONCE_KEY', 'XYZ');
    define('AUTH_SALT', 'XYZ');
    define('SECURE_AUTH_SALT', 'XYZ');
    define('LOGGED_IN_SALT', 'XYZ');
    define('NONCE_SALT', 'XYZ');

    with the same values ass my primary site, can this be the problem?

  15. meloniq
    Member
    Posted 3 years ago #

    Whats Your second WordPress installation URL?
    Did You add on "slave" installation to wp-config these lines?

    define('CUSTOM_USER_TABLE', 'MainBlogPrefix_users');
    define('CUSTOM_USER_META_TABLE', 'MainBlogPrefix_usermeta');

    If You can't login perhaps You missed lines above, if You can't access "wp-admin" perhaps You are "Orphan" (user without roles)

  16. Sven01
    Member
    Posted 3 years ago #

    I did uninstall and re-install, now I can login, but I still have different logins for the blogs :)
    first is 4lol.eu and second stoofvlees.eu , still more blogs waiting, but first these 2 must work good ...

  17. meloniq
    Member
    Posted 3 years ago #

    Whole informations to make this integration are in posts above...
    I dont know how to explain it more clearly...

    If You still have got problems to setup it correctly, make a custom order via email: http://blog.meloniq.net/kontakt/

  18. Alex.R
    Member
    Posted 3 years ago #

    Meloniq do you have an alternative in regards to my issue with cookies? Thanks.

  19. meloniq
    Member
    Posted 3 years ago #

    I can check and test it in a next few days... but now, I need to hurry a lil, deadline of one project is really close:/

  20. Alex.R
    Member
    Posted 3 years ago #

    No problem brother, thanks in advance.

  21. meloniq
    Member
    Posted 3 years ago #

    Sorry for long awaiting for answer (forgot about this topic)...

    I tested above solution on one of my websites and it works fine except one thing, transfer login between WordPress installs... correct settings should be:

    1. Install WordPress with the same "secret key", in one database but with different prefix -> https://api.wordpress.org/secret-key/1.1/

    2. For all WP installs activate plugin WP Orphanage
    http://wordpress.org/extend/plugins/wp-orphanage/

    3. For "slave" WP installs add to wp-config.php data of main blog user tables

    define('CUSTOM_USER_TABLE', 'MainBlogPrefix_users');
    define('CUSTOM_USER_META_TABLE', 'MainBlogPrefix_usermeta');

    4. After this one step You can't access wp-admin, right? so add 2 new meta for admin user via phpMyAdmin (or any other equal panel) - add it to "MainBlogPrefix_usermeta"

    user_id => 1
    meta_key => SlaveBlogPrefix_user_level
    meta_value => 10

    user_id => 1
    meta_key => SlaveBlogPrefix_capabilities
    meta_value => a:1:{s:13:"administrator";s:1:"1";}

    5. Now You can access admin panel, but still login is not transfered between WP installs, so...
    Open all Your wp-config.php files and paste the same values (off course change domain to Yours before paste)

    define('COOKIE_DOMAIN', '.YourMainDomain.com');
    define('COOKIEPATH', '/');

    $baseurl = 'http://www.YourMainDomain.com';
    $cookiehash = md5($baseurl);
    define('COOKIEHASH', $cookiehash);
    define('AUTH_SALT', 'AUTH_SALT'.COOKIEHASH);
    define('LOGGED_IN_SALT', 'LOGGED_IN_SALT'.COOKIEHASH);
    define('AUTH_COOKIE', 'AUTH_COOKIE'.COOKIEHASH);
    define('SECURE_AUTH_COOKIE', 'SECURE_AUTH_COOKIE'.COOKIEHASH);
    define('LOGGED_IN_COOKIE', 'LOGGED_IN_COOKIE'.COOKIEHASH);
    define('TEST_COOKIE', 'TEST_COOKIE'.COOKIEHASH);

    6. Delete all cookies for Your domain and test how login works right now;)

    P.S. Hope that didn't missed any step, and this tips will be usefull for You;)

  22. lindaloustarr
    Member
    Posted 3 years ago #

    Thank you so very, very much Meloniq I hope your showcase was awesome - as a WP newbie I don't quite understand the following step 1:

    1. Install WordPress with the same "secret key", in one database but with different prefix - I show the following (below) in my main (root) wp install wp-config file: (which one of these would be the same "secret key" & do you mean that same secret key would be put into all (in my case 3 separate wp installs) wp-config files?, but what do you mean by "but with different prefix" - I thought these same following keys were to be placed in "all" wp-config" files that are in subfolders that will be sharing the same database for users?

    define('AUTH_KEY', ';44&x^=0sb)^iB^aX3QHi|B)vlU&{H!1E)+ox]gU-95.ot:JI-Dz&8o{_]#M`U}I');
    define('SECURE_AUTH_KEY', 'YiCcwv;>[+u5tZjJ,1 ;3v.Ee/QA1jvKtxUS0A+`F+a)2[|._TC5S)wjc$O *@T*');
    define('LOGGED_IN_KEY', '9$RGp_cEA-.#QHFg_QkuM 2*1JTFG$$*OB#/r}my]#%erLLb?5s]LEbN`.N,(nC6');
    define('NONCE_KEY', 'D`ORTu?46S{l-+x&/p@A7(@y <EO>]K~E,2<y0Vz5WOWXMMcFCpgz(g5_y6Gg&n}');
    define('AUTH_SALT', '_Rt1Z|Yow20Qjo/s!apsmaxxA%W~z6-`YQg*K-DHU:T$-eKm/b(|@N6SXlpe+gqc');
    define('SECURE_AUTH_SALT', '&$m-xjmMfljajrt>(KzKqvq$GoqMedh>dp{#.Mq^e-d&b$:OQ+FOH_@_aBphjk[G');
    define('LOGGED_IN_SALT', ']x*1s7cDUW+Bz#7Ag{1VK#ld#DYcEGLQ-yk6TDiH+Ct?wo@hvr4-.L3qnf&}IY r');
    define('NONCE_SALT', 'mH%<mcG-awU4!.VO|B/0x5fK}Br4Xl~nA^f-[aZsGSh(}IAse,TU8r4hB|NA) +W');

    Thank you so very much for your time in helping with this issue; please forgive my WP innocence at this point - I just want to be sure I understand exactly what to do here since I've already done quite a bit of work on the main wp install and I am a bit afraid I might mess something up & undo everything I've done already . . .

  23. Alex.R
    Member
    Posted 3 years ago #

    No worries meloniq, I've been working a lot myself, so I didn't miss much. I have a problem with WP-Orphanage, it collects all the orphans throughout my wp network and gives them all one user role, unfortunately I can't have that.

    When members register on a particular province sub-domain they are automatically assigned a user role based on their selection on the registration page as a Job Seeker, or Employer.

    Link: http://on.jobortunity.ca/wp-login.php

    I've followed the instructions to the tea, cleaned cookies on all browsers, and tested still no luck. Would there be a more custom way to do this? Perhaps something that would work for 2 user roles?

    ======

    lindaloustarr you should not display your secret key on the forums.. what meloniq meant was when you have 2 different blogs, each wp-config should have same secret key.. Go to: https://api.wordpress.org/secret-key/1.1/ - what ever key is generated, copy and replace your current secret key in blog 1, and add the very same key to blog 2..

    BLOG 1 - NEW SECRET KEY
    BLOG 2 - SAME NEW SECRET KEY AS BLOG 1

    ----------------------------- THIS IS YOUR CURRENT SECRET KEY-----

    define('AUTH_KEY', ';44&x^=0sb)^iB^aX3QHi|B)vlU&{H!1E)+ox]gU-95.ot:JI-Dz&8o{_]#M`U}I');
    define('SECURE_AUTH_KEY', 'YiCcwv;>[+u5tZjJ,1 ;3v.Ee/QA1jvKtxUS0A+`F+a)2[|._TC5S)wjc$O *@T*');
    define('LOGGED_IN_KEY', '9$RGp_cEA-.#QHFg_QkuM 2*1JTFG$$*OB#/r}my]#%erLLb?5s]LEbN`.N,(nC6');
    define('NONCE_KEY', 'D`ORTu?46S{l-+x&/p@A7(@y <EO>]K~E,2<y0Vz5WOWXMMcFCpgz(g5_y6Gg&n}');
    define('AUTH_SALT', '_Rt1Z|Yow20Qjo/s!apsmaxxA%W~z6-`YQg*K-DHU:T$-eKm/b(|@N6SXlpe+gqc');
    define('SECURE_AUTH_SALT', '&$m-xjmMfljajrt>(KzKqvq$GoqMedh>dp{#.Mq^e-d&b$:OQ+FOH_@_aBphjk[G');
    define('LOGGED_IN_SALT', ']x*1s7cDUW+Bz#7Ag{1VK#ld#DYcEGLQ-yk6TDiH+Ct?wo@hvr4-.L3qnf&}IY r');
    define('NONCE_SALT', 'mH%<mcG-awU4!.VO|B/0x5fK}Br4Xl~nA^f-[aZsGSh(}IAse,TU8r4hB|NA) +W');

    ----------------------------------------------

    You should never share your secret key with anyone online. Extreme Security Risk!

    As for different prefix, when you install your WordPress Blog, you will see something like wp_ and the option to change this. It's good practice to change them, making it harder for hackers to figure them out ;) for example instead of wp_ change it to a number prefix 911_ or 12345_ etc. My prefixes contain numbers and letters, I suggest you do the same. For a website like mine, I have 13 blogs running, and I made a note as to which province each prefix belongs to.. Taking notes in everything is key. If you have Word or Excel, both are great to keep track of everything you do on your website. Notes are key..

  24. lindaloustarr
    Member
    Posted 3 years ago #

    Thank you :) & Thank you for the information I needed to understand about in my question. I certainly wouldn't do this again (reveal the keys) & will change now!
    Linda Lou

  25. meloniq
    Member
    Posted 3 years ago #

    RE: lindaloustarr
    Explain of step number 1:
    a. Create one new database for all of WP installs, lets say "MyNewDB",
    b. In wp-config.php file of main and slave blogs set the same values which You will generate on below site:
    https://api.wordpress.org/secret-key/1.1/

    define('AUTH_KEY', 'XYZ');
    define('SECURE_AUTH_KEY', 'XYZ');
    define('LOGGED_IN_KEY', 'XYZ');
    define('NONCE_KEY', 'XYZ');

    c. Then install first main WP blog with table prefix "wp_" (as WP default prefix for tables)
    d. Second blog You already can't install with the same table prefix so lets change it for example to "blog2_", third WP with "blog3_" etc...

    RE: Alex.R
    In Your case that You need more then one user role, You should to skip step with WP-Orphanage, and make a "hardcoding" inside of file "wp-includes/capabilities.php", means edit prefix for "capabilities" meta and perhaps for "user_level"
    Piece of informations: http://wordpress.org/support/topic/wordpress-25-share-users-table

  26. lindaloustarr
    Member
    Posted 3 years ago #

    Thank you Meloniq :) - one last question before I brave this new territory . . . if I make a brand new database for my current root wp install (that will be the same database used for the 2nd & 3rd in sub-directories; if I understand you correctly) won't I lose all my current changes that I have already made on my main wp install? (I don't have any users at this point but I have made a huge amount of customizations to it). Also, I understand that I'm using the same database for all installs so it would stand to reason that I am also using the same username & password on all wp-config files?

    Wishing you many blessings. You are gratefully appreciated :)
    Linda Lou

  27. meloniq
    Member
    Posted 3 years ago #

    Yes, one database for all wordpress installs (if You have already installed "root blog" use his database to install second and third wordpress, if not - create new one).

    You will not loose anything what You already made on Your "root blog", for this You have to set different "prefix" for every wp install (but make a backup of DB, just for a case that something goes wrong).

    Yes, You should use the same username and password for Your database as in "root blog".

  28. Alex.R
    Member
    Posted 3 years ago #

    RE: Alex.R
    In Your case that You need more then one user role, You should to skip step with WP-Orphanage, and make a "hardcoding" inside of file "wp-includes/capabilities.php", means edit prefix for "capabilities" meta and perhaps for "user_level"
    Piece of informations: http://wordpress.org/support/topic/wordpress-25-share-users-table

    Thanks meloniq, I'll give it a read and try that method tonight, I just got back home from work, need to unwind first.. lol I'll let you know what the result is. =)

    P.S. How's the weather in Poland?.. I'm in Canada, and it's getting bloody cold out..

  29. meloniq
    Member
    Posted 3 years ago #

    Users which gonna use sub-directories instead of sub-domains should add 2 additional parametres into wp-config.php:

    define('ADMIN_COOKIE_PATH', '/');
    define('SITECOOKIEPATH', '/');
  30. Keshav Saini
    Member
    Posted 3 years ago #

    @meloniq I have a small confusion in the last step

    define('COOKIE_DOMAIN', '.YourMainDomain.com');
        define('COOKIEPATH', '/');
    
        $baseurl = 'http://www.YourMainDomain.com';
        $cookiehash = md5($baseurl);
        define('COOKIEHASH', $cookiehash);
        define('AUTH_SALT', 'AUTH_SALT'.COOKIEHASH);
        define('LOGGED_IN_SALT', 'LOGGED_IN_SALT'.COOKIEHASH);
        define('AUTH_COOKIE', 'AUTH_COOKIE'.COOKIEHASH);
        define('SECURE_AUTH_COOKIE', 'SECURE_AUTH_COOKIE'.COOKIEHASH);
        define('LOGGED_IN_COOKIE', 'LOGGED_IN_COOKIE'.COOKIEHASH);
        define('TEST_COOKIE', 'TEST_COOKIE'.COOKIEHASH);

    I have defined my security keys by editing default config files. Now do I need to replce the value in above code also or should I just copy paste as it is. I mean do I change the code after the line

    $baseurl = 'http://www.YourMainDomain.com';

    or it is to be pasted like this only after replacing the domain name?

Topic Closed

This topic has been closed to new replies.

About this Topic