• Codd

    (@ranjangoyal)


    Hi All,

    When users register on my main site, it uses the WordPress database. The accounts share the same username and password.

    Now when users login to my main site, I want the user to login into WordPress automatically. How can I do this?

    Auto Login between wordpress and bbpress is working.

    To achieve this I set a cookie to match that of wordpress cookie(In case we use wordpress login form to login) in the following manner. I call this script after logging into main site.

    $cookiehash = md5($blog_directory_web_path);
    
    $siteCookiePath = '/blog/forum/';// WordPress is working with bbpress
    
    define('COOKIE_DOMAIN', false);
    
    $expiration = 0;
    if($remember){
    
    $expiration = $expire = time() + 1209600;
    
    }else{
    
    $expiration = time() + 172800;
    $expire = 0;
    }
    
    $data = $username . '|' . $expiration;
    
    $key = hash_hmac('md5', $data, 'phrase 1');
    $hash = hash_hmac('md5', $data, $key);
    $cookie = $username . '|' . $expiration . '|' . $hash;
    
    setcookie('wordpress_'.$cookiehash, $cookie, $expire, $siteCookiePath, COOKIE_DOMAIN);
    
    setcookie('wordpress_'.$cookiehash, $cookie, $expire, '/', COOKIE_DOMAIN);

    Cookie is set but auto login is not working.

    Am I paasing correct values to cookie?
    Is there anything else I need to do?

    Following links are useless.

    http://wordpress.org/support/topic/81942
    http://mu.wordpress.org/forums/topic.php?id=4056
    http://codex.wordpress.org/WordPress_Cookies

    I am using 2.6.1.

    Please help.

    Regards,
    Ranjan

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

    (@ranjangoyal)

    In addition to the above, I also tried but never successful. Am I making a mistake here?

    $url = "http://site.com/demo/makeover/blog/forum/bb-login.php";
    $re = "http://site.com/demo/makeover/blog/";
    $_wp_http_referer = "/demo/makeover/blog/forum/bb-login.php";
    
    $curlPost = "user_login=".$username."&password=".$password."&re=".$re."&_wp_http_referer=".$_wp_http_referer;
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 10);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
    curl_exec($ch);
    curl_close($ch);
    Thread Starter Codd

    (@ranjangoyal)

    I also tried other way round.

    Ist I activated sessions in WordPress and then I changed the following function:

    function wp_generate_auth_cookie($user_id, $expiration) {
    	$user = get_userdata($user_id);
    
    	$key = wp_hash($user->user_login . '|' . $expiration);
    	$hash = hash_hmac('md5', $user->user_login . '|' . $expiration, $key);
    
    	/********************************/
    	$_SESSION['userid'] = $user_id;
    	$_SESSION['user'] = $user->user_login;
    	/*******************************/
    
    	$cookie = $user->user_login . '|' . $expiration . '|' . $hash;
    
    	return apply_filters('auth_cookie', $cookie, $user_id, $expiration);
    }

    Code in between
    /********************************/
    /*******************************/
    is added by me and I am able to register sessions but these session variables are not visible on the cakephp side means on mainsite.

    any directions and any help is highly appreciated.

    Regards,
    Ranjan

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

The topic ‘Cakephp wordpress bbPress auto login’ is closed to new replies.