2

There is session data being saved on sub.domain.com and I'd like to use that data in domain.com.

I confirmed that they both have the same session save path (by echoing ini_get('session.save_path') in both)

I've tried putting ini_set('session.cookie_domain', '.sub.domain'); on domain.com but that didn't work. (I have also removed the preceding .).

I also tried adding session_set_cookie_params(0, '/', '.domain.com'); in front of each session_start(), but that didn't work either.

I would like to be able to use the $_SESSION data in domain.com from what is set in sub.domain.com.

What can I do for this to work?

Thanks!


UPDATE: I figured out (at least one way) of how to do this, but not sure why my answer works. I guess my question would now be, Why does renaming the session name solve this? using the same session cookie domain (?) makes more sense to me.
Seems like setting this domain creates a new session $_SESSION['domain'] (where 'domain' is interchangeable in the session_name('domain') function.)

0

1 Answer 1

2

adding the following to each file fixed this:

session_name("domain");
session_set_cookie_params(0, '/', '.domain.com');
session_start();

Does anyone know why re-naming the session fixes this? It's that first line that made this all work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.