zen of coding

Sharing CakePHP session with another app

This question pops up once in a while: “How do I share session data with a third-party application?”

Thankfully the answer is pretty simple, just make sure that the session (cookie) name is the same for both apps.
In CakePHP it’s set in the core.php… Configure::write(‘Session.cookie’, ‘CAKEPHP’);

  • thnx Teknoid!
    And if you want to share it across multiple subdomains:
    http://www.cake-toppings.com/2008/10/04/set-the-session-cookie-to-the-top-level-domain/

  • Pingback: Set the session cookie to the top level domain | Cake Toppings()

  • teknoid

    @primeminister

    Nice. Well done on the site, as well.

  • kiran

    hi, i want to know whether a cake app and a non cake subdomain app can work well if cake app is example.com and non cake part is services.example.com. Is it possible? What precuations are needed to take to make both work well?
    The subdomain app will use same database as used by cake app on main domain.

  • teknoid

    @kiran

    I’ve never actually tested this situation, so I cannot give you an accurate answer. Please take a look at the post above by primeminister. I think it covers what you are looking to do…
    Also double check at the google group, I’m sure someone there might have a specific answer.

  • Chirayu

    my folder structure
    /htdocs/mainsite
    /app
    /cake
    /vendors
    .htaccess
    index.php
    README

    /htdocs/childsite
    /config
    /controllers
    /locale
    /models
    /plugins
    /test
    /tmp
    /vendors
    /views
    /webroot
    .htaccess
    app_controller.php
    app_helper.php
    app_model.php
    index.php
    if I create a session with $this->Session->write(‘User’,$user); in main site and redirect it to child site, my session data is not being accessed. I am not getting User data with $this->Session->read(‘User’) in child site.

    Can anybody help me ?

  • @Chirayu

    pr($_SESSION); what do you see?
    It seems like you are on shared host and sometimes they have all sorts of strange security features in-place that could possibly cause some problems there. Hard to guess.

  • chirayu

    Hi tekno, here is the session values.
    Array ( [Config] => Array ( [userAgent] => bc2b15193fd333c5666514e9cb360c36 [time] => 1236369514 [rand] => 1001972704 [timeout] => 10 ) )

  • chirayu

    Well, I am not shared host but I have created subdomain on my local webserver with
    DocumentRoot /var/www/html/caken
    ServerName caken

    DocumentRoot /var/www/html/chirayu
    ServerName chirayu

  • @Chirayu

    Did you read the comment posted by primeminister? Seems like it might address your issue, other than that I, unfortunately, don’t really have another suggestion. Maybe someone on IRC or the google group can provide an answer.

  • Pingback: Sharing CakePHP Session with another App « Myles Kadusale’s Blog()

  • Hello
    My folder structure
    mysite/
    app
    cake
    vendors
    blog

    Here blog is wordpress blog. I want to find session value from app to blog

    any body help me please

  • It not work with Cake 1.3.2. How can I do? Could you help me please?

  • ncg777

    Works not it does.

%d bloggers like this: