rss

Jun
09

CakePHP Sharing sessions between apps on the same domain

Posted (Amit) in General, PHP on 09-06-2010

6

Few days back i was working on two separate CakePHP applications, suddenly there was a need to maintain session between these two separate apps working on the same domain. Let me explain a bit more.

Cake-logo
Cake-logo
Image via Wikipedia

I was having two apps (i)wishlist (ii) lighthouse

These are two separate apps under the root folder having the directory structure as:
/htdocs
/wishlist
/app
/config
….
/lighthouse
/app
/config ….

By default the sessions are created relative to the apps directory, and this was the problem i was dealing with, not a big thing but i spent a lot of time figuring this, but for you its will work like a charm.

Steps that i follow to make the two apps share sessions between them.
1. Edit “core.php” for wishlist and the lighthouse and add the line
ini_set(‘session.cookie_path’, “/”);
This is to direct the CakePHP app to create the session on the root

2. The Session.cookie name should be same for the two apps

3. The Session.salt should be same for the two apps

4. Security.level should be low in both the apps

This is it what is required. Let me know if you are still stuck with the things, happy coding.

Share

Comments (6)

Hello Amit
I am facing a same problem on my local host to be setup with two cakephp applications, can I get your mobile number so that we can discuss.
 
Mine is 9325660481.

Hi Amit,
This solution is not working on different version of cake 1.3 and 2.1.
 
Thanks.

Amit

Will have a look at it Ram

Excellent post. I will be experiencing a few of these issues as well.

.

My website: news of the day

It’s very effortless to find out any topic on net as compared to textbooks, as I found this piece of writing at this web site.

I drop a leave a response each time I appreciate a article on a site or I have something
to contribute to the discussion. It is triggered by the passion communicated in the post I looked at.
And after this article CakePHP Sharing sessions between apps on the same domain | Amit Yadav.
I was moved enough to drop a leave a responsea response ;-) I actually do have a couple of questions for you if it’s okay. Could it be simply me or do a few of the responses come across like written by brain dead visitors? :-P And, if you are writing on additional online sites, I’d
like to follow everything new you have to post. Could you
make a list every one of all your communal sites like your linkedin profile, Facebook page or twitter feed?

Post a comment



Amit Yadav is Stephen Fry proof thanks to caching by WP Super Cache