Gags
Gags

Reputation: 3829

Share PHP Session across domain (main and sub domain)

Suppose the domain I am working on is www.example.com and it has a link shop which takes the user to subdomain shop.example.com

Now on shop.example.com when user add product to cart the the cart information is stored in $_SESSION['prd'] variable.

This session variable is available and count of cart items is perfectly displayed in shop.example.com but problem arises when i go to example.com then this session variable is not there.

I tried adding below line at the end of .htaccess

php_value session.cookie_domain ".example.com"  

but this gives 500 error.

Upvotes: 0

Views: 762

Answers (2)

Willian Santana
Willian Santana

Reputation: 41

I had a similar problem, however, this solution was good for me, perhaps will help others in the future

edit you php.ini

session.cookie_domain = ".exemple.com"

or in you script php

session_set_cookie_params(0, '/', '.example.com');

session_start();

if you have problems try add this in your php.ini

suhosin.session.cryptdocroot = Off

suhosin.cookie.cryptdocroot = Off

Upvotes: 0

DigiDamsel
DigiDamsel

Reputation: 106

As simple as it may seem did you try removing the quotes from around your subdomain?

php_value session.cookie_domain .example.com

I've not got the complete solution working yet, but this at least doesn't give any errors.

Upvotes: 1

Related Questions