Integrating wordpress authentication with an exist

2020-03-05 03:19发布

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

id 
name 
email 
password 
status

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

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.

1条回答
姐就是有狂的资本
2楼-- · 2020-03-05 04:04

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

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

Update:

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

From Using wordpress login functions

查看更多
登录 后发表回答