我正在寻找解决方案,但我什么也没找到。wp_signon()不保存cookie ==不能登录
我想让AJAX登录。这些scipt正在发送正确的数据和响应:错误或正确的登录数据。在成功重新加载页面之后...用户仍未登录。 我试图强制设置cookie,但没有成功。
我使用强制ssl管理员(如果这很重要)。
function ajax_login(){
global $user_ID;
if (!$user_ID) {
// First check the nonce, if it fails the function will break
check_ajax_referer('ajax-login-nonce', 'security');
// Nonce is checked, get the POST data and sign user on
$info = array();
$info['user_login'] = $_POST['username'];
$info['user_password'] = $_POST['password'];
$info['remember'] = true;
$user_signon = wp_signon($info, true);
if (is_wp_error($user_signon)){
echo json_encode(array('loggedin'=>false, 'message'=>__('Get lost.')));
} else {
wp_set_current_user($user_ID);
wp_set_auth_cookie($user_ID);
echo json_encode(array('loggedin'=>true, 'message'=>__('Wait stupid, im redirecting...')));
}
}
die();
}
请问您能帮我吗?我不知道什么是错的。 (在这个地方之前一切看起来都很好,数据发送正确,var_dump($ info)也返回正确的数据)。