且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 wordpress 身份验证与现有用户数据库集成

更新时间:2023-11-13 17:00:46

为什么要重复信息?您还必须采取措施在两个数据库之间获得一致的用户管理.

Why duplicate the information? You would also have to take measures to get a consistent user management between the two databases.

我建议使用现有数据库作为使用此插件的 WordPress 的身份验证源:http://wordpress.org/extend/plugins/external-database-authentication/

I suggest using the existing database as the authentication source for WordPress using this plug-in: http://wordpress.org/extend/plugins/external-database-authentication/

更新:

要允许用户已经登录到 WordPress,请在他们登录您的网站时设置 WordPress 身份验证 cookie.为此,您可以包含所需的最少 WordPress 代码并调用 wp_setcookie() 函数.

To allow users to be already logged in to WordPress, set the WordPress authentication cookie when they login on your website. You do this by including the minimum required WordPress code and call the wp_setcookie() function.

// include the wordpress files necessary to run its functions
include('../classpages/wp-config.php'); // this includes wp-settings.php, which includes wp-db.php, which makes the database connection
include(ABSPATH . WPINC . '/pluggable-functions.php');

// use wordpress's function to create the login cookies
// this creates a cookie for the username and another for the hashed password, which wordpress reauthenticates each time we call its wp_get_current_user() function
wp_setcookie($user_login, $user_pass, false, '', '', $cookieuser);

来自使用wordpress登录功能