Login procedure without using plugin: it seems like cookie is not set!
-
Hi guys, I’m new in wordpress and i’m trying to implement a login procedure relying only on wordpress core API.
I don’t know why this code doesn’t work:
` ……
$login_data = array();
$login_data[‘user_login’] = $email; //i’m using email as username…
$login_data[‘user_password’] = $password;
$login_data[‘remember’] = $remember;
$user = wp_signon( $login_data, false );
if(is_wp_error($user)){
…..
} else {
$user_id = $user->ID;
wp_set_auth_cookie($user_id);
wp_set_current_user($user_id);
}
if(is_user_logged_in())
echo “User “.$user_id.” Logged in!!”;`
So, as you can see, i added some control to see if my user is actually logged in and it is! But when i move in the home page i lose my authentication, so i think there are some problem with the wp_set_auth_cookie(). For this reason i also used the wp_validate_auth_cookie() after setting cookie and i see it returns false: is it the core of the matter? Someone can help me, please? Anyways I’m sorry for my english ??
- The topic ‘Login procedure without using plugin: it seems like cookie is not set!’ is closed to new replies.