1 (edited by Nick_c 2007-03-02 03:41)

Topic: [Solved] Login Integration with CakePHP

Hi everyone,

I've searched the forums, but I haven't found a similar problem, so thanks for taking the time to help.

I'm attempting to integrate punBB into a new site I'm creating. The site uses the CakePHP framework. However, for user management, I would prefer to use punBB's built in user management. Here are my directory and url layouts.

/root/webdev/mysite/
/root/webdev/mysite/app/  <-- tons of directories and files for the cakephp framework
/root/webdev/mysite/forum/ <--- punbb

mysite.com/forum/ <-- punbb
mysite.com/posts/23 <--- modrewrite is used here. This maps to /root/webdev/mysite/app/post_controller.php

The framework uses mod_rewrite, which isn't a problem (The forum works perfectly).  The only reason I mention it is because I think (...maybe) that my problem has to do with include()'s pulling from the wrong directory. But I could be wrong.

So basically, no matter where a person is at on my site, I want the user to be able to log in. And if they are logged in, I'd like to be able to show that they're logged in.

I can get a user login box to show up. And I can actually get the user to log in. If they are at mysite.com/forum/, punbb shows they're logged in. But if they go to a nested directory, mysite.com/post/someid/, $pub_user shows that they're a guest.

Can anyone help me with this?

Thanks a lot.

Re: [Solved] Login Integration with CakePHP

What is $cookie_path in config.php set to?

Re: [Solved] Login Integration with CakePHP

Hi!

Here's part of my config file

$cookie_name = 'punbb_cookie';
$cookie_domain = '';
$cookie_path = '/';
$cookie_secure = 0;
$cookie_seed = '3295b72a';

define('PUN', 1);

Do I need to change the cookie_path?

Re: [Solved] Login Integration with CakePHP

Mmm, I'm not sure what the issue is: could you provide a link to your site?

Re: [Solved] Login Integration with CakePHP

I'm developing it locally, so I don't have a url to point you to.

I think I've cornered the problem. I've used the following code within test.php in several different places:

global $db, $pun_user, $pun_config;
define('PUN_ROOT', 'forum/');
require PUN_ROOT.'include/common.php';

print_r($pun_user);

I had to add the correct mod_rewrite every time I tested it. But it would work. The pun_user array would show that I was logged in.

However, if I put that same exact code within my CakePHP app, it doesn't work. $pun_user prints out that I'm a guest. I have no clue why this is happening.

I checked to see if there was some sort of conflicting cookie: but no. The only thing I can think of is that mod_rewrite has to do with it. But it really shouldn't. I mean, the code is able to pull the include files from punBB's directory. It's able to actually read pun_user. It's just showing that I'm not logged in.

Maybe it has to do with how pun_user is propagated.

I don't know. Any ideas?

Re: [Solved] Login Integration with CakePHP

Moved to Integration

Could CakePHP be the problem? Remember that for $pun_user to be used within a function it needs to be declared global in the function

Re: [Solved] Login Integration with CakePHP

Sweet jesus, I got it to work.

Ok. So, I found the first file that's called in CakePHP, which is the dispatcher (dispatcher.php). I add the following code to the top:

<?php
global $db, $pun_user, $pun_config;
define('PUN_ROOT', 'forum/');
require PUN_ROOT.'include/common.php';
?>

Then, in any controller or view (CakePHP terms) I just add the following code:

global $db, $pun_user, $pun_config;
print_r($pun_user); //use $pun_user here

Finally! Thanks for the help.