Mohan & me, we are working on the same project. And we have cracked the
Session sharing with cake and other applications. So a part of the
credit goes to him as well. memcached is a distant option for us, as we
cannot compile and install anything on the server(we will do that once
we have a dedicated server).

*warning* This is going to be long post. plus, spare my english.

Before going further, let me accept - this is an under-the-belt trick.
I welcome the gurus to better this code.
I have posted only the basic code to help anyone start off.

1. To inject a session into PHPBB (or any other application, even if it
doesnt follow OOP class methods).
create a vendor class in cake (/app/vendors/phpbb.php).
add the following code in that.

class PHPBB {

        var $userdata;
        var $sessionid;

        function login($user) {
                global $db, $phpbb_root_path, $phpEx, $userdata, $board_config,
$userdata, $user_ip;
                $phpbb_root_path = PHPBB_FORUM_PATH; //add it in your core.php
                include($phpbb_root_path . 'extension.inc');
                include($phpbb_root_path . 'common.'.$phpEx);
                $userdata = session_pagestart($user_ip, PAGE_INDEX);
                init_userprefs($userdata);
                $this->userdata = $userdata;
                $autologin = ( isset($HTTP_POST_VARS['autologin']) ) ? TRUE : 0;
                $admin = (isset($HTTP_POST_VARS['admin'])) ? 1 : 0;
                $this->sessionid = session_begin($user, $user_ip, 0, FALSE,
$autologin, $admin);
        }

        function logout($user) {
                global $db, $phpbb_root_path, $phpEx, $userdata, $board_config,
$userdata, $user_ip;
                $phpbb_root_path = APP . 'webroot' . DS .'forums' . DS;
                include($phpbb_root_path . 'extension.inc');
                include($phpbb_root_path . 'common.'.$phpEx);
                $userdata = session_pagestart($user_ip, PAGE_INDEX);
                session_end($userdata['session_id'], $userdata['user_id']);
        }

}

2. in your controller (eg: users_controller.php) call vendors('phpbb');
3. after authenticating the user, before other session initialisation,
add this
$bb = new PHPBB();
$bb->login($this->User->data['User']['id']);
unset($bb);
// ... other code follows,

4. however, before adding any other session data, you have to do this.
because phpbb has polluted your session. (if someone has a better
technique, let me know)

$this->Session->renew();
$this->Session->write('User.id', $this->User->data['User']['id']);
...
...

Thats it.
--------------------------------------------
Now if you have to inject a CAKE Session from another application, its
a little more complex and its not fully tested. So I will be brief with
this one.
1. create a cake_inc.php in your app/config (you can put it anywhere,
but I think config is the best place)
2. add these defines and includes in that
if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('ROOT')) {
         define('ROOT', dirname(dirname(dirname(__FILE__))));
}
if (!defined('APP_DIR')) {
         define('APP_DIR', basename(dirname(dirname(__FILE__))));
}

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
         define('CAKE_CORE_INCLUDE_PATH', ROOT);
}
if (!defined('WEBROOT_DIR')) {
         define('WEBROOT_DIR', basename(dirname(__FILE__)));
}
if (!defined('WWW_ROOT')) {
         define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
         if (function_exists('ini_set')) {
                  ini_set('include_path', ini_get('include_path') . 
PATH_SEPARATOR .
CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS);
                  define('APP_PATH', null);
                  define('CORE_PATH', null);
         } else {
                  define('APP_PATH', ROOT . DS . APP_DIR . DS);
                  define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
         }
}

include APP_PATH . 'config' .DS  .'core.php';
include CAKE_CORE_INCLUDE_PATH .DS . 'cake' . DS . 'basics.php';
include CAKE_CORE_INCLUDE_PATH .DS . 'cake' . DS . 'config' . DS.
'paths.php';
include CAKE_CORE_INCLUDE_PATH .DS . 'cake' . DS . 'libs' . DS .
'object.php';

3. I am interested in injecting a session into cake, nothing else. add
these following lines:
include CAKE_CORE_INCLUDE_PATH .DS . 'cake' . DS . 'libs' . DS .
'security.php';
include CAKE_CORE_INCLUDE_PATH .DS . 'cake' . DS . 'libs' . DS .
'session.php';

4. Now you can call this cake_inc.php in your other application. In
phpBB, add at the top of page in login.php
include PATH_TO_CAKE_CONFIG . '/cake_inc.php';
after successful login , add this
$cakesession = new CakeSession(null);
$cakesession = new CakeSession(null);
$cakesession->renew();
$cakesession->writeSessionVar("User.id",$row['user_id']);

5. Now go to your cake app's home page, you can see that user is logged
in.

6. It would be worthwhile to poke around and see if you can launch a
controller or a model like this. then it would be easy to use cake with
other applications.




If you poke around and include required app_controllers & app_models (I
will try that later :))

cheers to Cake


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to