PHP的WordPress的登陆密码变更

I'm trying to build a simple wordpress password change script of my own (well, based on a plugin really) - the password is successfully changed - but it logs me out after the change completes! Below is the code used. Can anyone see where I'm being logged out and how to prevent it? Thanks!

$update = $wpdb- query($wpdb- prepare("UPDATE {$wpdb- users} SET `user_pass` = %s WHERE `ID` = %d",array(wp_hash_password($_POST['admin_pass1']),$user_ID)));
if(!is_wp_error($update))
 wp_cache_delete($user_ID,'users');
 wp_cache_delete($user- user_login,'userlogins');
 wp_logout();
 if (wp_signon(array('user_login'= $user- user_login,'user_password'= $_POST['admin_pass1']),false)):
 wp_redirect(admin_url());
 endif;
 ob_start();
处理计划方案

After resetting password you have to set/reset cookies ()
like this

$update = $wpdb- query($wpdb- prepare("UPDATE {$wpdb- users} SET `user_pass` = %s WHERE `ID` = %d",array(wp_hash_password($_POST['admin_pass1']),$user_ID)));
if(!is_wp_error($update))
 wp_cache_delete($user_ID,'users');
 wp_cache_delete($user- user_login,'userlogins');
 wp_logout();
 if (wp_signon(array('user_login'= $user- user_login,'user_password'= $_POST['admin_pass1']),false)):
 wp_redirect(admin_url());
 endif;
 ob_start();
}else{
 wp_set_auth_cookie( $current_user_id, true);

To reset the password you'd better use wordpress functions like wp_check_password and wp_set_password because of integration with other applications/plugins.


我正在尝试搭建自身的简易wordpress登陆密码变更脚本制作(很好,具体上是根据软件)-登陆密码已取得成功变更-但变更进行后却销户了我!下面是应用的编码。谁能看到我被销户的地区和怎样避免它撤出?感谢!



 $ update = $ wpdb- query($ wpdb- prepare( UPDATE {$ wpdb- users} SET`user_pass` =%s WHERE`ID` =%d,array(wp_hash_password($ _ POST ['admin_pass1']),$ user_ID))); 

if(!is_wp_error($ update))
{
wp_cache_delete($ user_ID,’users’);
wp_cache_delete($ user- user_login,'userlogins');
wp_logout();
if(wp_signon(array('user_login'= $ user- user_login,'user_password'= $ _ POST ['admin_pass1']),false)):
wp_redirect(admin_url( ));
endif;
ob_start();
}

处理计划方案

重设登陆密码后,您务必设定/重设cookie()



 $ update = $ wpdb- query($ wpdb- prepare( UPDATE {$ wpdb- users} SET`user_pass` =%s WHERE`ID` =%d,array(wp_hash_password($ _ POST ['admin_pass1']),$ user_ID))); 

if(!is_wp_error($ update))
{
wp_cache_delete($ user_ID,’users’);
wp_cache_delete($ user- user_login,'userlogins');
wp_logout();
if(wp_signon(array('user_login'= $ user- user_login,'user_password'= $ _ POST ['admin_pass1']),false)):
wp_redirect(admin_url( ));
endif;
ob_start();
} else {
wp_set_auth_cookie($ current_user_id,true);
}


要重设登陆密码,最好是应用诸如wp_check_password和wp_set_password之类的wordpress涵数,由于与别的运用程序流程/软件的集成化。