简体   繁体   English

WordPress共享用户数据库进行登录

[英]Wordpress share users database for Login

What i'm trying to do is to share the users credentials between 2 or more Wordpress installations on the same database. 我想做的是在同一数据库的2个或更多Wordpress安装之间共享用户凭据。 I read many tutorials, and forums on this one but none gave me a clear answer on this one. 我阅读了很多教程和论坛,但没有一个给我明确的答案。 So according to Wordpress Codex ([1]), all I have to do is add the code below to wp-config.php (child installation) in order to switch tables for users and usermeta: 因此,根据Wordpress Codex([1]),我要做的就是将以下代码添加到wp-config.php(子安装)中,以便为用户和usermeta切换表:

define( 'CUSTOM_USER_TABLE', 'main_users' );
define( 'CUSTOM_USER_META_TABLE', 'main_usermeta' );

This allows me to login with the root sites' username and password but I'm getting the message 这使我可以使用根站点的用户名和密码登录,但是却收到消息

You do not have sufficient permissions to access this page. 您没有足够的权限访问此页面。

Then I'm completely lost. 然后我完全迷路了。 I checked the _capabilities inside the database as stated at [1] but still getting that message. 我按照[1]所述检查了数据库内部的_capabilities,但仍然收到该消息。

Any help would be really appreciated since I'm working on this one for 3 days. 由于我为此工作了3天,因此我们将不胜感激。 Thanks! 谢谢!

[1] http://codex.wordpress.org/Editing_wp-config.php#Custom_User_and_Usermeta_Tables [1] http://codex.wordpress.org/Editing_wp-config.php#Custom_User_and_Usermeta_Tables

This is not quite the right way to go about it. 这不是正确的解决方法。 If you succeed with this, I think you'd be opening yourself up to some serious security vulnerabilities. 如果您成功做到这一点,我认为您将面临一些严重的安全漏洞。

Instead, you should look into creating a WordPress Multisite install. 相反,您应该研究创建WordPress Multisite安装。 The details of Multisite are here: http://codex.wordpress.org/Create_A_Network 多站点的详细信息在这里: http : //codex.wordpress.org/Create_A_Network

You can also learn more about Multisite here: http://mashable.com/2012/07/26/beginner-guide-wordpress-multisite/ 您还可以在此处了解有关多站点的更多信息: http : //mashable.com/2012/07/26/beginner-guide-wordpress-multisite/

Trying to get two separate installs to share information isn't the normal way to attack this problem... most of the times with this requirement, I've seen people use Multisite. 试图获得两个单独的安装来共享信息不是解决此问题的正常方法...在大多数情况下,出于这一要求,我已经看到人们使用Multisite。

Solution : 解决方案:

Our goal is to set up two WordPress websites which will share logins and the same users. 我们的目标是建立两个可以共享登录名和相同用户的WordPress网站。 Once a user has subscribed one 一旦用户订阅了一个

website, she would be able to access the other website with the same role and capabilities. 网站,她将能够访问具有相同角色和功能的其他网站。

step 1: In order to share the same users and usermeta tables, WordPress installations must share the same database. 步骤1:为了共享相同的用户和usermeta表,WordPress安装必须共享相同的数据库。 add prefix of first wordpress installation first_ and second wordpress installation table second_. 添加第一个wordpress安装first_和第二个wordpress安装表second_的前缀。 in same database. 在同一个数据库中。

step 2: When the first WordPress website is up and running, we can edit its configuration file. 步骤2:当第一个WordPress网站启动并运行时,我们可以编辑其配置文件。 Open /first/wp-config.php 打开/first/wp-config.php

and add the following lines above the 'stop editing' comment: 并在“停止编辑”注释上方添加以下几行:

 $table_prefix  = 'first_';
 define('WP_DEBUG', true);
 define( 'WP_DEBUG_LOG', true );
 define( 'WP_DEBUG_DISPLAY', false );
 @ini_set( 'display_errors', 0 );  

// custom users and usermeta tables
define( 'CUSTOM_USER_TABLE', $table_prefix . 'users' );
define( 'CUSTOM_USER_META_TABLE', $table_prefix . 'usermeta' ); 

/* That's all, stop editing! Happy blogging. */

step 3: We are done with the first installation. 步骤3:我们完成了第一次安装。 Next we have to copy wp-config.php from the first installation folder and 接下来,我们必须从第一个安装文件夹中复制wp-config.php并

paste it into the root folder of the second installation. 将其粘贴到第二个安装的根文件夹中。 Be careful to change the $table_prefix value accordingly: 请注意相应地更改$ table_prefix值:

open /second/wp-config.php.and add the following lines above the 'stop editing' comment: 打开/second/wp-config.php。并在“停止编辑”注释上方添加以下行:

 $table_prefix  = 'second_';
    define('WP_DEBUG', true);
    define( 'WP_DEBUG_LOG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    @ini_set( 'display_errors', 0 );

      // custom users and usermeta tables
     define( 'CUSTOM_USER_TABLE', 'first_users' );
     define( 'CUSTOM_USER_META_TABLE', 'first_usermeta' );

step 4: write in both wp-config.php for sharing cookies. 步骤4:在两个wp-config.php中编写共享Cookie。

    //Share cookies
   define('COOKIE_DOMAIN', '.xyz.com');
   define('COOKIEHASH', 'aee53c017c29dc0d3ae37253fc8cbfd8');

step 5: Open table "first_usermeta" and copy from column meta_key - first_capabilities and first_user_level to the second_capabilities and second_user_level. 步骤5:打开表“ first_usermeta”,然后从meta_key-first_capabilities和first_user_level列复制到second_capabilities和second_user_level。 在此处输入图片说明

step 6: When running the second installation, we should set a non-existent email address for admin user as WordPress finds a number of existing users from first_users table. 第6步:运行第二个安装时,我们应为admin用户设置一个不存在的电子邮件地址,因为WordPress从first_users表中找到了许多现有用户。

For more Detail https://kinsta.com/blog/share-logins-wordpress/. 有关更多详细信息, 请访问https://kinsta.com/blog/share-logins-wordpress/。

It's work for Me. 对我来说是工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM