我开发了一个使用PHP和MySQL的网站,它已经有一个登录和注册表单.(myweb.com
)
我在这个网址上添加了wordpress myweb.com/blog
我想在WordPress上禁用登录和注册页面并强制用户使用我的.基本上将我的登录与WordPress集成,以便用户将在两个站点上登录.
我的网站members
表看起来像这样.并且所有注册用户都存储在此处.我的数据库中的密码使用哈希值md5()
id | name | email | password
和WordPress结构是这样的,目前是空的
ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name
我尝试按照这里提到的步骤
但是我在第254行得到了这个错误 var_dump($user);
object(WP_Error)#620 (2) { ["errors"]=> array(1) { ["invalid_username"]=> array(1) { [0]=> string(166) "ERROR: Invalid username. Lost your password?" } } ["error_data"]=> array(0) { } }
此外,所有用户信息都存储在members
我的网站上的表格中,而不是存储在WordPress的数据库中.
这是我的网站的登录代码,我最近也添加了WordPress登录.
/* * Login * * $email = email of user * $pass = user password (must already be in md5 form) * $url = url of page they are login from */ function login($email = '', $pass = '', $url = '', $sticky = false) { global $lang, $_db, $mod, $template_style; // Replace nasty things to stop sql injection $email = addslashes(strtolower($email)); $email = strip_tags($email); $email = htmlspecialchars($email, ENT_QUOTES); //get user id $sql = "SELECT `id`, `name`, `username` FROM `members` WHERE `email`='".mysql_real_escape_string($email)."' AND `pass` = '" . mysql_real_escape_string($pass) . "' LIMIT 0,1"; $q = $_db->query($sql); list($uid, $name, $username) = $_db->fetch_array($q); $login_check = $_db->num_rows($q); if ($login_check <= '0') //check if login matches { echo '0'; //login failed die; } /* * wordpress login * * read: * http://codex.wordpress.org/Function_Reference/wp_update_user */ $credentials = array(); $credentials['user_email'] = $email; $credentials['user_password'] = $pass; $credentials['remember'] = $sticky; // true/false $secure_cookie = false; // true / false $user = wp_authenticate($credentials['user_email'], $credentials['user_password']); if ( is_wp_error($user) ) { if ( $user->get_error_codes() == array('empty_email', 'empty_password') ) { //$user = new WP_Error('', ''); $user = wp_update_user(array ( 'user_login' => $name, 'user_email' => $email, 'user_pass' => $pass )); } } var_dump($user); wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie); do_action('wp_login', $user->user_login, $user); /* set login cookies */ set_login_cookie($uid, $pass, $sticky); //lock check lock_checker($uid); update_thisuser_online(); }
我是否必须从members
表格中复制所有内容并将其填入wp_users
或者是否有办法登录到wordpress而不会在2个不同的表格中存在重复数据?我不想在两个网站上都有2个登录和2个注册表单.
为什么wp_authenticate()
我的代码不会在上面验证?