• Hello all,
    I have a codeigniter website and it is the main website,it has phpmotion a video blog ,as it subsection.Now if a person comes to our main website,the user email is searched on phpmotion website.if the user is not registered,then the user is registered and logged into the phpmotion site automatically or if user email exists then,the session is started for that user and logged in automatically.This all happens when a user clicks on a phpmotion href link while logged in.So the user has a single login system.

    Now we have installed wordpress budypress and want to do the same automatic logic login/register.That is when a user logins into our codeigniter website,this user should be registered and logged into our wordpress buddypress website automatically,if user does not exists on wp or else just start sesssion and log him in.I have explained my scenario and it is a client requirement,so please do not come up with questions like ‘Why you want to achieve this etc..’.Instead please be kind to suggest an alternative as how to achieve this.

    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter debugger777

    (@debugger777)

    Hi
    I have fixed it,with help from other users in this wordpress blog.

    Here it is

    <?php ob_start();
    require($_SERVER[‘DOCUMENT_ROOT’].”/index.php”); // Include wordpress main index file,we get access to “all wp-function(not tested)” in our external file.
    define(‘WP_USE_THEMES’, false); // Do not show themes
    header(“HTTP/1.1 200 OK”); //Sometimes error occurs,so to fix we set headers

    $email = ‘someuser@somewhere.com’; //Get username or password from

    if (!email_exists($email))
    {
    echo ‘That E-mail doesn\’t belong to any registered users on this site,So registering….
    ‘;
    wp_create_user( ‘someuser’, ‘passme’, ‘someuser@somewhere.com’); // Creating WP User
    echo ‘This email id is now registered thanks—>’.$email;

    }
    else
    {
    echo “That E-mail id is already registered !! So, automatically signing in…”;
    $creds = array();
    $creds[‘user_login’] = ‘someuser’;
    $creds[‘user_password’] = ‘passme’;
    $creds[‘remember’] = true;
    $user = wp_signon( $creds, false ); // Sigining in a WP User

    if( is_wp_error($user))
    {
    echo ‘oops!! we got some error in sigining in ‘.$user->get_error_message();
    }
    else
    {
    echo ‘
    User is now logged in !!
    ‘;
    }

    }
    ob_end_flush();
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Login to wordpress from external website’ is closed to new replies.