views:

163

answers:

2

Hello Everyone, I have been busy integrating Wordpress to one of a CakePHP application.Last Monday I cracked the way to integrate it.Now another problem I faced was that Client wanted to auto login the users who are login in CakePHP side,I did that too and it works fine in local.I am using the Session Variable of CakePHP which is set in core.php of cakephp,in the Wordpress also.The Code snippet of the Auto Login plugin is : -

session_name("Cake_PHP_Session_Vars");
session_start();
function auto_login(){if (!is_user_logged_in()) {
    //determine WordPress user account to impersonate
    $user_login = 'guest';

   //get user's ID
    $sessVars = $_SESSION['User'];
    $user_id = $sessVars['id'];

    //login
    wp_set_current_user($user_id, $user_login);
    wp_set_auth_cookie($user_id);
    do_action('wp_login', $user_login);
}}add_action('init', 'auto_login');

It all works fine on the Local system but when I am putting it on Server,It is not working out.Please suggest me what could be the problem here. Thanks In Advance

+1  A: 

is your blog under a different subdomain like blog.domain.com. in that case, a new session would be created for blog visitor unless you do a work around.

does your domain change from domain.com to www.domain.com when you go from main site to blog? if thats the case, a new session is also created.

Funky Dude
No No...the Url to my Blog is http://www.MainSite.com/blog/that's It!
Nishant Shrivastava
@Funky Dude: I have a sumilar problem with subdomain,any ideas about the work around ?
Sourabh
+6  A: 

Hello Experts, Well I rectified the problem I was facing. I was just setting up the current user's from Cake Side to WP only through the User Id set in the Session variable.But there is a chance that incremented id's in Cake's User Table could be different and when we a are putting that into Wp_users table it could be different than that.so in the new plugin I just added some of the line in which retrieve the username of the Logged In user and then fetch the ID of that user,coz we know that there is 0 possibility of having two(or more) Users with same USERNAME.That's why we then fetch the Id of the Username we have in the Session and then use

wp_set_current_user($user_id, $user_name);

You all can see that I have replaced $user_login (that was by default set to Guest) with $user_name(fetched from the Session Variable).Now it is working fine.The main issue was that in my Local system Cake's Tables and Wordpress tables were Synced very nicely,but in server there was some problem with the synchronization.

Nishant Shrivastava