Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7934451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:39:04+00:00 2026-06-03T21:39:04+00:00

I am working with Cakephp and I have an issue maintaining session across subdomains.

  • 0

I am working with Cakephp and I have an issue maintaining session across subdomains. My problem is as follows:

  • Users login on ‘localhost/login’
  • If authenticated they are redirected to ‘customer.localhost/home’.

Currently Cake is creating a cookie for each domain ie localhost and customer.localhost.
This means that I cannot keep the session working for the user. Is there a way to make all cookies domain fixed to the parent domain with the goal of keeping the session working across subdomains?

I have tried entering this in my bootstrap but it has no effect:
ini_set(‘session.cookie_domain’, ‘.localhost’);

If you think this cannot be done please feel free to let me know so that I can move on from this frustrating problem.

Many thanks,

kSeudo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:39:06+00:00Added an answer on June 3, 2026 at 9:39 pm

    Sessions (CakePHP 2.x):

    To make the session cookie valid for all your subdomains and the top level domain, you actually need to set it yourself in your APP/config/bootstrap.php file:

    ini_set('session.cookie_domain', '.domain.com');
    

    Then, in your APP/config/core.php file, set Security to low:

    Configure::write('Security.level', 'low');
    

    “otherwise the referer_check will be set to the current HTTP_HOST in
    the CakeSession object line 441.”

    Sessions (CakePHP 3.x)

    The session cookie path defaults to app’s base path. To change this
    you can use the session.cookie_path ini value. For example if you want
    your session to persist across all subdomains you can do:

    Configure::write('Session', [
        'defaults' => 'php',
        'ini' => [
            'session.cookie_path' => '/',
            'session.cookie_domain' => '.yourdomain.com'
        ]
    ]);
    


    Cookies (CakePHP 2.x):

    On this page it explains that you can use the ‘domain’ variable:

    The domain name allowed to access the cookie.
    e.g. Use ‘.yourdomain.com’ to allow access from all your subdomains.

    Per their example code:

    <?php
    public $components = array('Cookie');
    public function beforeFilter() {
        parent::beforeFilter();
        $this->Cookie->name = 'baker_id';
        $this->Cookie->time =  3600;  // or '1 hour'
        $this->Cookie->path = '/bakers/preferences/';
        $this->Cookie->domain = 'example.com';
        $this->Cookie->secure = true;  // i.e. only sent if using secure HTTPS
        $this->Cookie->key = 'qSI232qs*&sXOw!';
        $this->Cookie->httpOnly = true;
    }
    

    Cookies (CakePHP 3.x):

    Read here.

    The domain that the cookie is available. To make the cookie available
    on all subdomains of example.com set domain to ‘.example.com’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on CakePHP, and I have my app working in my localhost.
I've been working in CakePHP and I got the following problem. I have a
I have a RESTful API set up and working with CakePHP using mapResources() and
I'm new to cakephp so have just been working through the cookbook and am
I am new to cakephp and have been working through the Apress book Beginning
let's say i have: http://some-domain/application/controller/action/parameter This is somehow working in cakePHP. Now I want
I'm working on a French language site built in CakePHP. I have tried multiple
My problem is that memcache logic inside my cakePHP application is not working on
I have installed CakePHP in my test server and it is working fine. When
I have a local cakephp 1.2 app which was working fine last night. Currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.