【问题标题】:Integrating wordpress authentication with an existing user database将 wordpress 身份验证与现有用户数据库集成
【发布时间】:2012-01-19 07:39:48
【问题描述】:

我有一个带有用户表的数据库,其中包含以下字段:

id 
name 
email 
password 
status

我的用户通过提供电子邮件和密码登录。我已经安装了一个路径为 mysite.com/news 的博客。

我想要的是,如果某些用户在我的网站上注册,它应该会自动在我的 wordpress 数据库中添加一行。我想获取我的用户表的所有记录并存储在 wordpress 用户表中。此外,如果有人登录我的网站,则在他们访问博客时也应该登录。

【问题讨论】:

标签: php sql wordpress


【解决方案1】:

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

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

更新:

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

// 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);

来自Using wordpress login functions

【讨论】:

  • 当我激活它的给予者 mysql 错误时它不起作用
  • 感谢它的完美工作。现在我想知道是否有用户登录我现有的站点并且他来博客。他的会话应该与我现有的站点会话相同。我该怎么做?
  • 这个函数保存在哪里?你能解释一下吗
  • 您需要在用户登录您的第一个网站后运行它。因此,在您将用户登录到网站后,立即运行我展示的 WordPress 特定代码。
  • 如果你需要查找 wp_setcookie() 的选项,你可以在这里找到它们:72.233.56.142/Function_Reference/wp_setcookie
猜你喜欢
  • 1970-01-01
  • 2011-07-06
  • 2022-09-23
  • 2022-01-04
  • 2021-02-10
  • 2019-04-02
  • 2014-09-28
  • 2021-06-02
  • 1970-01-01
相关资源
最近更新 更多