1

I am using cakephp 2.x for my main application and wordpress for blog, now my main application is on my domain called example.com and my blog is in sub domain called blog.example.com. i want to login user in my blog site also when user login in my main site (example.com).

in cakephp i have use

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

in my myapp/app/Config/bootstrap.php

and

$this->Cookie->domain = '.example.com';

in beforeFilter() of my appController

while in WP i had used

define('COOKIE_DOMAIN', 'example.com');

Now scenario is,

  1. When i open example.com first and login with my username/password and then after i open blog.example.com then my blog site show me as logged in user (i have just different header menu for logged in user and not-logged in user)
  2. When i open my blog.example.com first, then after i open example.com and login in example.com and refresh the blog.example.com then it won't display header for login user(i.e not login the user, means not detecting the session cookie of main domain).

i determine the logic like (i'm not sure but), if wp site open up first then it create it's own session cookie and if cakephp site open first then wp site uses session cookie from that. but what for point 2.

can anyone help me please?

Thanks

Dr Magneto
  • 981
  • 1
  • 8
  • 18

2 Answers2

0
header("Set-Cookie: cookiename=cookievalue; expires=thus, 14-march-2015 23:39:49 GMT; path=/; domain=subdomain.example.net");
Pang
  • 9,564
  • 146
  • 81
  • 122
Amit Verma
  • 31
  • 9
0

You can do like this :


    $this->Cookie->write('cookien_name','data array',true,'time');

This is not necessary to set domain name.if you not set domain name then it auto save domain name as '/'.
Please check this url also.
http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html

Akshay Sharma
  • 1,042
  • 1
  • 8
  • 21
  • my aim is not to write cookie. i have mention that i want use use common login, and for that we have to share cookie generated by session. – Dr Magneto Mar 16 '16 at 05:52
  • check this url hope this can be hep : http://stackoverflow.com/questions/15188261/single-sign-on-sso-between-wordpress-and-cakephp – Akshay Sharma Mar 16 '16 at 08:24