将 wordpress 身份验证与现有用户数据库集成 [英] Integrating wordpress authentication with an existing user database

查看:29
本文介绍了将 wordpress 身份验证与现有用户数据库集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含字段的用户表的数据库:

I have a database with a user table that has the fields:

id 
name 
email 
password 
status

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

My users login by giving the email and password. I have installed a blog that has the path mysite.com/news.

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

What I want is that if some user registers in my site it should automatically add a row in my wordpress database. And I want to fetch all my records of my user table and store in the wordpress user table. Also, if someone logs into in my site it should logged in when they go to the blog.

推荐答案

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

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登录功能

这篇关于将 wordpress 身份验证与现有用户数据库集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆