php - Cross domain session sharing does not work until site visited in browser -


i have script setup allows me communicate across 2 domains via javascript - foo.example.com bar.example.com.

when cross-domain request hits server make sure set access control headers follows (in kohana):

$this->response->headers('access-control-allow-origin', 'foo.example.com')); $this->response->headers('access-control-allow-credentials', 'true'); $this->response->headers('access-control-allow-methods', 'post, get, options'); 

i make sure kohana knows want share cookies across sub-domains:

cookie::$expiration = 60 * 60 * 24 * 14; cookie::$salt = 'salt-string-which-is-the-same-on-both-domains'; cookie::$httponly = true; cookie::$domain = '.example.com'; 

i've set javascript use single domain (as have iframes going cross-domain well):

document.domain = "example.com"; 

i use xhrfields property when making $.ajax() requests:

xhrfields: {     withcredentials: true } 

the problem

the problem have when used altogether perform cross-domain ajax request session on second instance bar.example.com doesn't read cookie(s) sent it. if dump session it's blank session shell.

however if hit second instance directly , try ajax scripts works expected. leads me believe issue reading cookie(s).

any ideas?

i believe have found causing issue. because both domains served separate instance have unique php environments running. code using native php session - when cookie sent second server gets id no data allocated.

it's visiting site manually triggers allocation of data automatically runs through authentication , authorisation procedure. going switch using database session in kohana. both instances point same db should resolve issue.

i'll post here confirm.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -