Access WordPress session from cake PHP site

This is quite difficulty for me. Please help.
I’ve a website created with cake PHP in root domain (say mysite.com) and a blog in a directory called “blog” (mysite.com/blog).
I have a register/login feature in PHP site.
So what I want here is, whenever a member login in the main site using the login form, whenever he open the blog (mysite.com/blog), he shoulb be as logged in as the same user logged in the main PHP site.
In the same way, whenever a new user sign-up with the registration form in the main PHP site, he should become an user in the wordpress blog.

Thanks.

Related posts

Leave a Reply

2 comments

  1. In your main site, you have to include WP’s functions by using wp_signon

    define('WP_USE_THEMES', false); //this disables the theme
    require('/blog/wp-blog-header.php'); //includes wordpress functions
    

    And then, you can auto-login a user in WP by using

    $credentials = array();
    $credentials['user_login'] = 'example';
    $credentials['user_password'] = 'plaintextpw';
    $credentials['remember'] = true;
    $user = wp_signon( $creds, false );
    if ( is_wp_error($user) ) {
    //login failed
    echo $user->get_error_message();
    }
    

    This should work fine, I hope this helps you.