1

I am trying to figure out how to use the php function setcookie() to set a cookie in domain X and exist in domain Y, so that I can accomplish Single Sign On. I think I am missing something, here is my code:

When on domain X and using the below code, it successfully created a cookie with domain set to X and path to /

setcookie('ssisid', $authentication['session']['session_id'], time() + 3600, '/');

When I tried going to domain Y, the cookie was not set.

When I tried adding in domain Y to the code:

setcookie('ssisid', $authentication['session']['session_id'], time() + 3600, '/', 'http://www.example.com');

where example.com is placeholder for my site, no cookie was created on either domain.

What am I missing?

user1015214
  • 2,733
  • 10
  • 36
  • 66
  • have you seen this post? -> http://stackoverflow.com/questions/4701922/how-does-facebook-set-cross-domain-cookies-for-iframes-on-canvas-pages – Marco Mura Nov 18 '14 at 16:19
  • Have you tried removing `http://` from the domain? – DampeS8N Nov 18 '14 at 16:21
  • @DampeS8N - yes, I only added http:// in when it didn't work without it – user1015214 Nov 18 '14 at 16:23
  • @MarcoMura - I'm not using any iframes, not sure if that makes a difference. How can I tell if a site doesn't allow cross browser cookies? The site I am connecting to should be able to accept these cookies because in their API docs it said they would. – user1015214 Nov 18 '14 at 16:28
  • That was an answer that said it can be done with iframe/javascript. That said please remember that cookies as far as i know are stored on Client Side not Server Side =) So you need to create the cookie correctly on Client Side ^_^ – Marco Mura Nov 18 '14 at 16:30

1 Answers1

2

I figured it out. My first code with just the path was correct. The issue was that I was in the Chrome incognito mode. I knew that and I had assumed that all tabs in incognito mode would be part of the same session and be able to pass cookies, but I guess not.

user1015214
  • 2,733
  • 10
  • 36
  • 66