WordPress.org

Ready to get started?Download WordPress

Forums

Auto Login/Logout (1 post)

  1. lightyearllc
    Member
    Posted 4 years ago #

    I've added wordpress as a folder into another site that requires members to login. Rather than force them to login again to the blog I've added the following code to the index.php page of the blog to automatically log them in if they've logged into the membership site:

    if (!is_user_logged_in()) {
    $field='login';
    $user_info = get_user_by($field, $_SESSION[SESS_USERNAME]);
    $user_login = $user_info->user_login;
    $user_level = $user_info->user_level;
    $user_id = $user_info->ID;
    wp_set_current_user($user_id);
    wp_set_auth_cookie($user_id);
    do_action('wp_signon', $user_id);
    }

    It works well and now I'm trying to automatically log them out from the blog when they logout from the memerbship site using the code:

    if ( is_user_logged_in() )
    {
    wp_logout();
    }
    else echo "Blog User is Not Signed In.";

    The problem I'm having is that the is_user_logged_in fuction always returns false, even when the blog is statig that I'm logged in.

    does anyone have experience with a similar solution?

    Thanx ..... Rick

Topic Closed

This topic has been closed to new replies.

About this Topic